如何将HTML格式化邮件发送给管理员。
与顾客不一样。管理员获得正确的邮件内容,但格式不正确,所以我想添加html css和其他格式化。
答案 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
变量与您...