【问题标题】:php smtp ssl html mail not workingphp smtp ssl html邮件不起作用
【发布时间】:2016-03-20 20:16:39
【问题描述】:

有人可以告诉我我已经上网并尝试了我能想到的一切我只收到纯文本电子邮件...

电子邮件部分正在工作的只是 HTML 内容,而不是原始代码而不是 html 格式的 $body(消息)。

这是我的代码:

    <?php
 require_once "Mail.php";

 $from = "Home Calendar <calendar@home>";
 $to = "Me Yahoo <me@yahoo.co.uk>, Me Gmail <me@gmail.com>";
 $subject = "TESTING PHP EMAIL";
 $body = "
<html>
    <head>
        <title>HTML email</title>
    </head>
    <body>
        <p>This email contains HTML Tags!</p>
    <table>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
        </tr>
        <tr>
            <td>Ricardo</td>
            <td>Wagemaker</td>
        </tr>
    </table>
    </body>
</html>
";

 $host = "ssl://mail.domain.co.uk";
 $port = "465";
 $username = "name@domain.co.uk";
 $password = "password";

$headers = array (
        "MIME-Version: 1.0",
        "Content-type: text/html; charset=ISO-8859-1",
        'From' => $from,
        'To' => $to,
        'Subject' => $subject
        );

 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body, $from, $subject);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("\n\n<p>Message successfully sent!</p>\n\n");
  }
 ?>

非常感谢

【问题讨论】:

    标签: php email ssl smtp


    【解决方案1】:

    没有帮助,但我终于想通了,这完全是因为我的标题中缺少新行“rn”..

    这是有效的修改。

    $headers = array (
        'MIME-Version' => '1.0rn',
        'Content-Type' => "text/html; charset=ISO-8859-1rn",
        'From' => $from,
        'To' => $to,
        'Subject' => $subject
     );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 2014-01-19
      • 2017-10-27
      • 2014-06-05
      • 2016-10-22
      • 1970-01-01
      • 2012-08-01
      相关资源
      最近更新 更多