mail()标题问题为html电子邮件 [英] mail() header problem for html email

查看:101
本文介绍了mail()标题问题为html电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为PHP网站写一个错误报告功能。我不能得到标题,以便电子邮件将显示为html。

I am trying to write a error reporting feature for a website in php. I cannot get the headers right so that the email will display as html.

这是代码:


Here is the code:

if( isset($_POST['submit']) )
{
    $browser = $_SERVER['HTTP_USER_AGENT'];
    $page = $_POST['page'];
    $email = $_POST['email'];
    $error = $_POST['error'];

    $message  =  "<html><body> \n";   
    $message .=  "Email: $email \n";
    $message .=  "Page: $page \n";
    $message .=  "OS/ Browser: $browser \n";
    $message .=  "Error: $error \n";
    $message .=  "</body></html> \n";

    $headers  = 'MIME-Version: 1.0' . '\r\n';
    $headers .= 'Content-type: text/html; charset="iso-8859-1"' . '\r\n';
    $headers .= 'From:  <code@website.com>' . '\r\n';
    $headers .= 'Reply-To: $email ' . '\r\n';
    $headers .= 'X-Priority: 1' . '\r\n';

    $subject  = "[ERROR REPORT] Page: " . $page;

    mail("myEmail@gmail.com", $subject, $message, $headers );

    $mesg = "Thank you for your report!";

}

?>


推荐答案

基本上重复我回答的内容另一个问题,我都是为了滚动你的 - 自己在大多数情况下,但是当涉及到邮件我衷心建议,使自己更容易,并使用像 Swift Mailer PHPMailer (按照这个顺序,我的钱)。

Basically repeating what I answered for another question, I'm all for rolling-your-own in most situations, but when it comes to mail I'd heartily recommend making it easier on yourself and using something like Swift Mailer or PHPMailer (in that order, for my money).

作为附加奖金(并假设您指定回复等),您的标记为垃圾邮件的机会也少得多。

As a side-bonus (and assuming you specify reply-to, etc), you also have much less chance of being tagged as spam.

编辑:也许这只是您使用的示例,但您的消息中没有实际的HTML。为什么不使用纯文本?是的,我会使用我建议的纯文本之一。

Maybe it's just the example you've used, but there's no actual HTML in your message. Why not just use plain text? And yes, I'd use one of the classes I suggest for plain text too.

这篇关于mail()标题问题为html电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆