Php邮件功能不以html格式发送

时间:2013-12-21 19:58:34

标签: php html email html-email

在PHP中,我正在尝试以HTML格式发送电子邮件。到目前为止我有这个

            $subject = "Password Reminder";
            $message = "Your password is <b>{$password}</b>.<br/><br/><br/><br/>me";
            $message = wordwrap($message, 70, "\r\n");
            $headers = 'From: me@gmail.com' . '\r\n' .
                'Reply-To: me@gmail.com' . '\r\n' .
                'X-Mailer: PHP/' . phpversion() . '\r\n' .
                'MIME-Version: 1.0\r\n' . '\r\n' .
                'Content-Type: text/html; charset=ISO-8859-1\r\n';

            mail($email, $subject, $message, $headers);

我遵循了这个指南:http://css-tricks.com/sending-nice-html-email-with-php/

但是当我收到电子邮件时,它会显示标签,我希望它将标签解释为html。

有谁知道什么是错的?

感谢。

1 个答案:

答案 0 :(得分:9)

这很可能是问题所在:'MIME-Version: 1.0\r\n' . '\r\n' .

在两个结束后,标题结束并且正文开始。因此,您的content-type text / html声明被解析为邮件正文,而它属于标题。

删除一个结束,它应该有效:

'MIME-Version: 1.0\r\n'

我也注意到你使用\r\n的单引号。您应该使用双引号,否则它们将被转义。你需要对它们进行解析。

 'From: me@gmail.com' . "\r\n" .
                'Reply-To: me@gmail.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion() . "\r\n" .
                'Content-Type: text/html; charset=ISO-8859-1'."\r\n".
                'MIME-Version: 1.0'."\r\n\r\n";