เขียนโค้ด ส่งเมล แบบ Prestashop ด้วย Mail :: Send
ใน Prestashop มี library สำหรับช่วยให้ เราส่งเมล ผ่าน ทาง SMTP หรือจะใช้ฟังก์ชั่น mail ของ php ในการส่งก็ได้ขึ้นอยู่กับ ความพร้อมของเครื่อง หรือ Host ที่เราใช้งานอยู่  โดย Prestashop เลือกใช้ PHP Mail library swiftmailerเป็น library สำหรับส่งเมล

ตัวอย่างโค้ด Prestashop สำหรับส่งเมล
การส่งเมลจากร้านค้า Prestashop มีสอง methods ให้เลือกคือ
1. Mail :: Send() เป็นการส่งเมลโดยใช้ template คือเก็บไฟล์ข้อความหรือเนื้อหาไว้ในไฟล์ template
รูปแบบ
Mail::Send($id_lang, $template, $subject, $templateVars, $to, $toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = _PS_MAIL_DIR_, $die = false)

2. Mail :: sendMailTest() ส่งเมลโดยไม่ต้องใช้ template ของ Prestashop
รูปแบบ
Mail::sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
ตัวอย่าง
    require(dirname(__FILE__).'/config/config.inc.php');
    require_once(dirname(__FILE__).'/init.php');
    $customer = new Customer();
    $customer->getByEmail('[email protected]');
    //Set the variables for the template:
    $templateVars['{firstname}'] = $customer->firstname;
    $templateVars['{lastname}'] = $customer->lastname;
    $templateVars['{src_img}'] = _PS_BASE_URL_.__PS_BASE_URI__.'download/blog_belvg.png'; //Image to be displayed in the message
    $id_land = Language::getIdByIso('en');     //Set the English mail template
    $template_name = 'template'; //Specify the template file name
    $title = Mail::l('Test Mail'); //Mail subject with translation
    $from = Configuration::get('PS_SHOP_EMAIL');   //Sender's email
    $fromName = Configuration::get('PS_SHOP_NAME'); //Sender's name
    $mailDir = dirname(__FILE__).'/mails/'; //Directory with message templates
    $toName = $customer->firstname.' '.$customer->lastname; //Customer name
    $fileAttachment['content'] = file_get_contents(_PS_BASE_URL_.__PS_BASE_URI__.'download/fb.zip'); //File path
    $fileAttachment['name'] = 'fileAttachment'; //Attachment filename
    $fileAttachment['mime'] = 'application/zip'; //mime file type
    $send = Mail::Send($id_land, $template_name, $title, $templateVars, $customer->email, $toName, $from, $fromName, $fileAttachment, NULL, $mailDir);
    if ($send)
        echo 'Done';
    else
        echo 'Error';
โดยที่ $template_name = 'template_name'; คือชื่อไฟล์ template ที่ต้องทำไว้สองรูปบบคือ HTML และ TXT แล้วเก็บไว้ ใน folder
mails/{lang}/template_name.html
mails/{lang}/template_name.text

กระทู้ล่าสุดจากเว็บบอร์ด
หัวข้อกระทู้
ตอบ
เปิดดู
ล่าสุด
คำสั่งเปลี่ยน User เพื่อรันคำสั่งบน Linux Ubuntu
โดย mindphp พ 20 ธ.ค. 2023 4:01 am บอร์ด Linux - Web Server
0
358
พ 20 ธ.ค. 2023 4:01 am โดย mindphp View Topic คำสั่งเปลี่ยน User เพื่อรันคำสั่งบน Linux Ubuntu
โหลดเอกสารแล้วเหมือนถูก blocked แก้ยังไงคะ
โดย Narisara อ 19 ธ.ค. 2023 10:52 am บอร์ด ถาม - ตอบ คอมพิวเตอร์
1
306
พฤ 21 ธ.ค. 2023 12:59 pm โดย mindphp View Topic โหลดเอกสารแล้วเหมือนถูก blocked แก้ยังไงคะ
มี software ไหนสามารถมาใช้แทน vmware ได้บ้างครับ ที่เป็นแบบ free หรือ license ไม่แพง
โดย Anonymous จ 18 ธ.ค. 2023 4:00 pm บอร์ด ถาม - ตอบ คอมพิวเตอร์
2
492
จ 18 ธ.ค. 2023 4:14 pm โดย mindphp View Topic มี software ไหนสามารถมาใช้แทน vmware ได้บ้างครับ ที่เป็นแบบ free หรือ license ไม่แพง
สอบถามวิธีเช็คสิทธ์ การเข้าชมกระทู้ และการตอบกลับกระทู้ ใน phpBB
โดย flook จ 18 ธ.ค. 2023 1:10 pm บอร์ด สอบถามปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM
3
781
ศ 22 ธ.ค. 2023 4:27 pm โดย flook View Topic สอบถามวิธีเช็คสิทธ์ การเข้าชมกระทู้ และการตอบกลับกระทู้ ใน phpBB
สอบถามฟิลด์ price lists ในหน้าตะกร้าสินค้า mooziicart
โดย Thanapoom1514 ศ 15 ธ.ค. 2023 12:26 pm บอร์ด Joomla Development
2
2886
ศ 15 ธ.ค. 2023 12:39 pm โดย Thanapoom1514 View Topic สอบถามฟิลด์ price lists ในหน้าตะกร้าสินค้า mooziicart
อัปเดตระบบการรักษาความปลอดภัยใหม่ของ Joomla 5.0.1 และ 4.4.1 เวอร์ชันล่าสุด
โดย Thanapoom1514 พฤ 14 ธ.ค. 2023 5:59 pm บอร์ด MindPHP News & Feedback
0
331
พฤ 14 ธ.ค. 2023 5:59 pm โดย Thanapoom1514 View Topic อัปเดตระบบการรักษาความปลอดภัยใหม่ของ Joomla 5.0.1 และ 4.4.1 เวอร์ชันล่าสุด
สอบถามปุ่มเลือกเอกสารกดแล้วมันไม่ขึ้น modal ในหน้าเพิ่มเมนู joomla 5 ครับ
โดย Thanapoom1514 พฤ 14 ธ.ค. 2023 11:45 am บอร์ด Joomla Development
2
2406
อ 19 ธ.ค. 2023 7:53 pm โดย Thanapoom1514 View Topic สอบถามปุ่มเลือกเอกสารกดแล้วมันไม่ขึ้น modal ในหน้าเพิ่มเมนู joomla 5 ครับ
สอบถามดู query เวลาโหลดหน้าเพจจากโปรแกรมไหน และใช้อย่างไรบ้างค่ะ
โดย eange08 พ 13 ธ.ค. 2023 2:54 pm บอร์ด SQL - Database
1
1172
พ 27 ธ.ค. 2023 1:18 pm โดย mindphp View Topic สอบถามดู query เวลาโหลดหน้าเพจจากโปรแกรมไหน และใช้อย่างไรบ้างค่ะ