无法使用opencart发送HTML邮件

时间:2015-10-10 07:24:35

标签: opencart

我正在尝试使用以下代码使用opencart发送HTML邮件

$mail = new Mail();

$namess = $this->request->post['name'];
$emailss = $this->request->post['email'];
$phoness = $this->request->post['phone'];
$phoness2 = $this->request->post['phone2'];
$enquiryss = $this->request->post['enquiry'];
$conve = $this->request->post['contactviae'];
$convp = $this->request->post['contactviap'];
if($conve == '1')
{
    $convee = "Yes";
}
else
{
    $convee = "No";
}
if($convp == '1')
{
    $convpp = "Yes";
}
else
{
    $convpp = "No";
}       

$body = "Hello Admin <br/><br/> You have recieved a request for product. The details for your product is as follow : 
<br/><br/>
<table border='1'>
<tr><td>Name</td><td>$namess</td></tr>
<tr><td>Email</td><td>$emailss</td></tr>
<tr><td>Phone No</td><td>$phoness</td></tr>
<tr><td>Secondary Phone</td><td>$phoness2</td></tr>
<tr><td>Enquiry</td><td>$enquiryss</td></tr>
<tr><td>Contact Via Email</td><td>$convee</td></tr>
<tr><td>Contact Via Phone</td><td>$convpp</td></tr>
</table><br/><br/>
Thanks & Regards
";

$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($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject("Request a product");
$mail->setHtml($body);

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

$mail->send();

当我尝试使用代码时,它正在发送带有HTML标记的邮件

如何使用上述代码发送HTML邮件?

1 个答案:

答案 0 :(得分:0)

$body = "Hello Admin <br/><br/> You have recieved a request for product. The details for your product is as follow :" 
. "<br/><br/>"
. "<table border='1'>"
. "<tr><td>Name</td><td>$namess</td></tr>"
. "<tr><td>Email</td><td>$emailss</td></tr>"
. "<tr><td>Phone No</td><td>$phoness</td></tr>"
. "<tr><td>Secondary Phone</td><td>$phoness2</td></tr>"
. "<tr><td>Enquiry</td><td>$enquiryss</td></tr>"
. "<tr><td>Contact Via Email</td><td>$convee</td></tr>"
. "<tr><td>Contact Via Phone</td><td>$convpp</td></tr>"
. "</table><br/><br/>"
. "Thanks & Regards";

使用上面的代码来定义html代码值。