Home > other >  Opencart 3.0.2.0 sending email with mail() funtion
Opencart 3.0.2.0 sending email with mail() funtion

Time:06-03

I want to send an email to everyone who subscribes to my newsletter. In order to do this i wrote the following code inside a method i created in catalog->controller->common->footer.php.

         $to = "[email protected]";
         $subject = "-5% Έκπτωση στο ioannoustores.com";
         
         $message = "Χρησιμοποιήστε το εκπτωτικό κουπόνι στις αγορές σας και κερδίστε 5% έκπτωση. Ο κωδικός σας είναι: " . $res . " και ισχύει για 7 ημέρες.";
         
         
         $header = "From:[email protected] \r\n";
         
         
         
         mail($to,$subject,$message,$header);

I used the exact same code in opencart 2.1 and it worked but in 3.0.2.0 it doesn't work. Can someone help me please?

CodePudding user response:

$to = "[email protected]";
         $subject = "-5% Έκπτωση στο ioannoustores.com";
         
         $message = "Χρησιμοποιήστε το εκπτωτικό κουπόνι στις αγορές σας και κερδίστε 5% έκπτωση. Ο κωδικός σας είναι: " . $res . " και ισχύει για 7 ημέρες.";
         
         
         $header = "From:[email protected] \r\n";

try this:

$mail = new Mail($this->config->get('config_mail_engine'));
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');

$mail->setTo($to);
$mail->setFrom('[email protected]');
$mail->setSender(html_entity_decode('Shop Name', ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject), ENT_QUOTES, 'UTF-8'));
$mail->setHtml($message);
$mail->send();
  • Related