0

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

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

4

1 回答 1

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

如您所见,标有注释的两行正在设置电子邮件的 HTMLTXT 正文,而发送给管理员的电子邮件仅设置 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'));

你应该完成了。不要忘记用 Yours 更改$subject$text变量...

于 2013-11-11T14:31:03.793 回答