[英]Opencart send email in custom Script
I have a script in my opencart, made by myself, and want to make it send an email, but I think that when I try to get email parameters they return null
. 我的opencart中有一个脚本,由我自己制作,并希望让它发送一封电子邮件,但我认为当我尝试获取电子邮件参数时,它们会返回
null
。
Here is my code: 这是我的代码:
$email_to = "somewhere@example.com";
$config = new Config();
$mail = new Mail();
$mail->protocol = $config->get('config_mail_protocol');
$mail->parameter = $config->get('config_mail_parameter');
$mail->hostname = $config->get('config_smtp_host');
$mail->username = $config->get('config_smtp_username');
$mail->password = $config->get('config_smtp_password');
$mail->port = $config->get('config_smtp_port');
$mail->timeout = $config->get('config_smtp_timeout');
$mail->setTo($email_to);
$mail->setFrom("nuno@[mydomain].com");
$mail->setSender("nuno@[mydomain].com");
$mail->setSubject("test send mail");
$mail->setText("test message body text");
$mail->send();
When I try calling: echo $config->get('config_mail_protocol');
当我尝试调用时:
echo $config->get('config_mail_protocol');
it returns null
. 它返回
null
。
Do not create new instances of Config
but just simply call 不要创建
Config
新实例,只需简单地调用即可
$email_to = "somewhere@example.com";
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($email_to);
$mail->setFrom("somewhere@example.com");
$mail->setSender("somewhere@example.com");
$mail->setSubject("test send mail");
$mail->setText("test message body text");
$mail->send();
I've faced problems sending mail with the previously mentioned codes. 我在使用前面提到的代码发送邮件时遇到了问题。 Opencart mail variables have been changed since opencart 2.
自opencart 2以来,Opencart邮件变量已被更改。
This is the code for opencart 2.3 这是opencart 2.3的代码
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$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($order_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($this->load->view('mail/order', $data));
$mail->setText($text);
$mail->send();
Code block copied straight from catalog/model/checkout/order.php
直接从
catalog/model/checkout/order.php
复制代码块
I hope somebody will find this useful. 我希望有人会觉得这很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.