<?php
$subject = $this->language->get('text_subject');
$message = "este es el mensaje";
$html = "<html><head><title>Documento sin título</title></head><table>
<tr>
<td>Ticket</td>
<td>Status</td>
<td>action</td>
<td>account type</td>
</tr>
<tr>
<td>1</td>
<td>COMPLETED</td>
<td>CREATE</td>
<td>DEMO</td>
</tr>
</table><body></body></html>"
$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($customer_query->row['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($html);
$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
$mail->send();?>
我有这个代码发送电子邮件php,$html
包含代码html发送邮件,但只出现html代码并且文本没有出现。代码中有错误吗?
答案 0 :(得分:0)
您正在设置要发送的HTML和TXT消息。这意味着两封邮件都会发送,并且根据您的电子邮件客户端,只显示一条。如果您的电子邮件客户端可以显示HTML消息并且此消息已打开,则仅显示HTML消息,否则仅显示TXT消息。 HTML和TXT消息不应该包含不同的内容,但是相同 - 一种是HTML格式,一种是普通的TXT替换,用于不支持HTML格式的客户端。
在这种情况下,如果您要发送上述HTML消息,则TXT替换应为
$message = "Documento sin título\r\n";
$message .= "Ticket: 1\r\n";
$message .= "Status: COMPLETED\r\n";
$message .= "action: CREATE\r\n";
$message .= "account type: DEMO\r\n";
也许你需要的是发送两封电子邮件(也许是两个不同的用户?)...