在opencart中向管理员发送html格式的警报邮件

时间:2013-11-11 13:24:49

标签: php opencart

如何将HTML格式化邮件发送给管理员。

与顾客不一样。管理员获得正确的邮件内容,但格式不正确,所以我想添加html css和其他格式化。

1 个答案:

答案 0 :(得分:3)

好的,我会在这里发送答案,但我认为你应该做更多的研究并为自己尝试一些东西。通常用这段代码发送客户邮件:

$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($order_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($order_info['store_name']);
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
// THIS IS THE IMPORTANT PART
$mail->setHtml($html);
$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
// END OF IMPORTANT PART
$mail->send();

正如您可以看到标有注释的两行是设置电子邮件的HTML TXT正文,而发送给管理员的电子邮件只设置了TXT正文:

    $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($this->config->get('config_email'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($order_info['store_name']);
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
// THIS IS THE IMPORTANT PART
$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
// END OF IMPORTANT PART
$mail->send();

所以在这里,在管理邮件发送部分,添加以下行:

$mail->setHtml($html);

$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));

你应该完成。不要忘记更改$subject$text变量与您...