【问题标题】:send email with php and html content [closed]发送带有 php 和 html 内容的电子邮件 [关闭]
【发布时间】:2014-11-18 12:04:31
【问题描述】:
      <?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代码而没有出现文本。代码有错误?

【问题讨论】:

  • 您使用哪个类来发送电子邮件。必须有一些选项来设置要发送的 HTMLemail。我希望在你的脚本中某个地方定义了 $html
  • 我已经修改了代码
  • 正文设置为 $message,即“este es el mensaje”——这就是您要发送的内容吗?
  • 是的,这就是我要发送的内容

标签: php html email opencart send


【解决方案1】:

您正在设置要发送的 HTML 和 TXT 消息。这意味着会发送两条消息,并且根据您的电子邮件客户端,仅显示一条消息。如果您的电子邮件客户端可以显示 HTML 消息并且此选项已打开,则仅显示 HTML 消息,否则仅显示 TXT 消息。 HTML 和 TXT 消息不应包含不同但相同的内容 - 一种是 HTML 格式,另一种是用于不支持 HTML 格式的客户端的纯 TXT 替代。

在这种情况下,如果您要发送上述 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";

也许您需要发送两封电子邮件(也可能是发送给两个不同的用户?)...

【讨论】:

    猜你喜欢
    • 2014-07-13
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 2020-06-12
    • 2023-03-21
    相关资源
    最近更新 更多