带标题的PHP Mail()函数 [英] PHP Mail() Function with headers

查看:70
本文介绍了带标题的PHP Mail()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与PHP mail()函数一起使用标头时,我总是很挣扎. 问题一直是一样的,去年这个时候,只要我记得,它就让我发疯.

I always struggle when using headers along with the PHP mail() function. The problem is always the same, last year, this time, as long as I remember, it drives me mad.

问题在于标题只是简单地显示在电子邮件中.

The problem is that the headers are simply displayed in the email message.

示例收到的邮件:

http://nl.tinypic.com/view .php?pic = 63va5z& s = 8#.U8PmeED8rbw

来源:

$onderwerp = "Bedankt voor uw bestelling met order nummer # ".$row['id'];
$ontvanger = "customer@customer.be";
$reply = "reply@reply.be";
//$reply = htmlspecialchars($_POST['je_email']); 

$headers = "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "MIME-Version: 1.0\r\n";    

$headers .= "Reply-To: Webmaster < reply@website.be >\r\n"; // reply-adres
//$headers .= "Cc:  webmaster@website.be , crewlid@website.be \r\n"; //copy
//$headers .= "Bcc:  crew@website.be \r\n"; // blind copy
$headers .= "From: TEST SOME NAME | GW8 <$reply>\r\n"; // de afzender van de mail
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "X-Priority: 1\r\n"; // 3 voor onbelangrijk 
$headers .= "Priority: Urgent\r\n";
$headers .= "Importance: High\r\n"; // Low voor onbelangrijk
$headers .= "X-MSMail-Priority: High\r\n"; // Low voor onbelangrijk  

$bericht = "<strong>TEST</strong>"; 

mail($ontvanger,$onderwerp,$bericht,$headers);

我使用哪个代码段,总是有同样的问题.. 电子邮件内容中显示的标题,如屏幕截图所示.

Which snippet I use, always the same problem.. Headers displayed in email content, as shown in screenshot.

有人知道我该如何解决吗?我强烈感觉这是服务器端的问题.

Does anybody know how I can fix this ? I have a strong feeling this is a server-side problem..

推荐答案

如果您不熟悉PHP的mail()函数,最好使用已建立的邮件解决方案.

It would be better to use established mailing solutions instead of PHPs mail() function if you're not experienced with that.

一些提示:

可读性和防止错误

出于可读性和编程目的-考虑将标头实现为数组.而不是在每行中添加\r\n,您可以像这样工作.在mail()功能中将邮件组合在一起时,可以implode()邮件.

For readability and programming purposes - think about implementing the headers as array. Instead of adding \r\n in every line you could work like that. When building together the mail in the mail() function you can implode() it.

// Building headers.
$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859';
$headers[] = 'X-Mailer: PHP/'. phpversion();
// ...

// Sending mail.
mail($ontvanger, $onderwerp, $bericht, implode(PHP_EOL, $headers));

发送HTML邮件

我建议在发送html时以multipart MIME messages的形式发送邮件.这与您的方法不同.因为在消息中解释起来并不容易.也许可以通过以下链接进行尝试: http://webcheatsheet.com/php/send_email_text_html_attachment.php

I recommend to send the mails as multipart MIME messages when sending html. This differs from your approch. Because it's not that easy to explain in a message. Maybe try it with that link: http://webcheatsheet.com/php/send_email_text_html_attachment.php

例如,我使用了多部分mime消息来通过PHP发送带有自定义附件的HTML邮件.

I've used multipart mime messages for example to send HTML mails with custom attachments via PHP.

没有必要注意不同标题的顺序.但是,将它们分组并从最重要的部分开始是一种很好的做法.

There is no necessarity of paying attention to the order of the different headers. But it's some sort of a good practice to group them and start with the most important ones.

这篇关于带标题的PHP Mail()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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