gpt4 book ai didi

php - Opencart 在自定义脚本中发送电子邮件

转载 作者:可可西里 更新时间:2023-11-01 12:30:21 25 4
gpt4 key购买 nike

我的 opencart 中有一个脚本,是我自己制作的,我想让它发送一封电子邮件,但我认为当我尝试获取电子邮件参数时,它们会返回 null

这是我的代码:

    $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();

当我尝试调用时:echo $config->get('config_mail_protocol'); 它返回 null

最佳答案

我在使用前面提到的代码发送邮件时遇到了问题。 Opencart 邮件变量自 opencart 2 以来已更改。

这是 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();

直接从catalog/model/checkout/order.php复制代码块

我希望有人会觉得这很有用。

关于php - Opencart 在自定义脚本中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16041146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com