php 完整的邮件标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/566182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:06:41  来源:igfitidea点击:

Complete mail header

phpemail

提问by johnnietheblack

I need a set of mail headers to attach to my mail()function in PHP. I send emails with HTML in them, and sometimes services like Yahoo Mailblock them. Therefore I need to make sure that I am at least providing the right headers.

我需要一组邮件头来附加到我mail()在 PHP 中的函数。我发送带有 HTML 的电子邮件,有时像Yahoo Mail这样的服务会阻止它们。因此我需要确保我至少提供了正确的标题。

My code:

我的代码:

// To send HTML mail, the 'Content-type' header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: MyCompany <[email protected]>' . "\r\n";  

Is there anything else I should add?

还有什么我应该补充的吗?

回答by Rohit Dubey

    $headers  = "From: testsite < [email protected] >\n";
    $headers .= "Cc: testsite < [email protected] >\n"; 
    $headers .= "X-Sender: testsite < [email protected] >\n";
    $headers .= 'X-Mailer: PHP/' . phpversion();
    $headers .= "X-Priority: 1\n"; // Urgent message!
    $headers .= "Return-Path: [email protected]\n"; // Return path for errors
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

回答by Joseph Tary

Most MUA's insert a lot of extra headers; however, here is sort of the bare minimum you can expect.

大多数 MUA 插入了很多额外的标题;但是,这是您可以期望的最低限度。

To: 
Subject:
Date: 
MIME-Version:
Content-type: 

If you using HTML, then you should probably be using multipart messages--but it's not strictly necessary.

如果您使用 HTML,那么您可能应该使用多部分消息——但这并不是绝对必要的。

回答by ólafur Waage

When defining if a sender is a possible spammer, many services check if the domain of the sender looks like a dialup user.

在定义发件人是否可能是垃圾邮件发送者时,许多服务会检查发件人的域是否看起来像拨号用户。

Quote from Wikipedia:

引自维基百科:

One e-mail anti-spam technique: checking the domain names in the rDNS to see if they are likely from dialup users, dynamically assigned addresses, or other inexpensive internet services. Owners of such IP addresses typically assign them generic rDNS names such as "1-2-3-4-dynamic-ip.example.com." Since the vast majority, but by no means all, of e-mail that originates from these computers is spam, many spam filters refuse e-mail with such rDNS names.

一种电子邮件反垃圾邮件技术:检查 rDNS 中的域名,看它们是否可能来自拨号用户、动态分配的地址或其他廉价的 Internet 服务。此类 IP 地址的所有者通常会为其分配通用 rDNS 名称,例如“1-2-3-4-dynamic-ip.example.com”。由于来自这些计算机的绝大多数(但绝不是全部)电子邮件是垃圾邮件,因此许多垃圾邮件过滤器拒绝使用此类 rDNS 名称的电子邮件。

回答by Jasper

Did the mail really come from 'mycompany.com'? I've had problems with some mail services blocking if it didn't really come from the SMTPserver that the mail says it does.

邮件真的来自“mycompany.com”吗?如果某些邮件服务实际上不是来自邮件所说的SMTP服务器,我就会遇到一些问题。

A way around this, for me, was making the from to be [email protected] and adding a reply-to, being the person who sent the mail using my system.

对我来说,解决这个问题的方法是将 from 设为 [email protected] 并添加一个reply-to,即使用我的系统发送邮件的人。

回答by james.garriss

The RFCs for both IMF and MIME define the minimal set of headers, so this would be a good place to start.

IMF 和 MIME 的 RFC 定义了最小的标头集,因此这将是一个很好的起点。

For IMF, look here: http://tools.ietf.org/html/rfc5322#section-3.6

对于 IMF,请看这里:http: //tools.ietf.org/html/rfc5322#section-3.6

For MIME, look here: http://tools.ietf.org/html/rfc2045#section-3

对于 MIME,请看这里:http: //tools.ietf.org/html/rfc2045#section-3

回答by Malachi

The link below could be of some use defining the mandatory headers as:

下面的链接可能有一些用处,将强制性标头定义为:

  • Date:The date the message was originated/written.

  • From:The person "responsible" for the message.

  • 日期:消息产生/编写的日期。

  • 来自:消息的“负责人”。