简体   繁体   English

必需的邮件标头

[英]Required Mail Headers

I have a website in which I send a confirmation mail as part of the registration process.我有一个网站,我在其中发送确认邮件作为注册过程的一部分。

Some time ago, I had some troubles with the mails I sent since I used no headers (PHP mail function).前段时间,由于没有使用headers(PHP邮件功能),我发送的邮件遇到了一些麻烦。

Once I put some headers, I've gotten more responses from users, but I suspect that not every message reaches its destination.一旦我放了一些标题,我就收到了更多用户的回复,但我怀疑并不是每条消息都到达了目的地。

How can I be sure that the messages reach their destination?我如何确保消息到达目的地?

Which are the headers that can be considered a 'must'?哪些标题可以被视为“必须”?

This is the code of my SendMail function这是我的 SendMail 函数的代码

mail($to,
    $subject,
        $message,
            "MIME-Version: 1.0\n".
            "Content-type: text/plain; charset=ISO-8859-1; format=flowder\n".
            "Content-Transfer-Encoding: 8bit\n".
            "Message-Id: <" . md5(uniqid(microtime())) . "@mysite.com>\n".
            "Return-Path: <admin@mysite.com>\n".
            "X-Mailer: PHP v".phpversion()."\n".
            "From: admin@ mysite.com");

You should use external library for working with e-mails in php like PhpMailer , SwiftMailer or Zend_Mail .您应该使用外部库来处理 php 中的电子邮件,例如PhpMailerSwiftMailerZend_Mail All your problems will go away.你所有的问题都会迎刃而解。

The headers need a white space at the bottom to separate the header from main body.标题需要在底部留出一个空格来将标题与主体分开。 Tools like Spam Assassin will give you a big mark down for that.像垃圾邮件刺客这样的工具会给你一个很大的分数。

Also you should use \\r\\n as a line terminator instead of just \\n此外,您应该使用\\r\\n作为行终止符,而不仅仅是\\n

From PHP.net来自 PHP.net

Multiple extra headers should be separated with a CRLF (\\r\\n).多个额外的标题应该用 CRLF (\\r\\n) 分隔。

This is a working mail function I'm using for html mail and variable $return is defined to get error report from mail server in case of fail delivery.这是我用于 html 邮件的工作邮件函数,变量 $return 被定义为在传递失败的情况下从邮件服务器获取错误报告。

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$from.'>' . "\r\n";
$return = '-f'.$from;

@mail($to, $subject, $msg, $headers, $return);

you can see more detail at here sugunan.com您可以在此处查看更多详细信息sugunan.com

The headers seems quite good to me.标题对我来说似乎很好。 The only glitch I see is an extra whitespace in the From header.我看到的唯一故障是 From 标题中的额外空格。

I'm sure you already checked it, but just in case ...我确定你已经检查过了,但以防万一......

"From: admin@ mysite.com");
  should be (?)
"From: admin@mysite.com");

The headers look ok, except for the details pointed by @Eineki.除了@Eineki 指出的细节之外,标题看起来还可以。 Also if you are using Windows you need to send the $to param in the form "user@mail.com" and not "Username ", because it may cause trouble, due to the way the mail() function is implemented on windows platform, the "to" address may be parsed incorrectly.此外,如果您使用的是 Windows,您需要以“user@mail.com”而不是“Username”的形式发送 $to 参数,因为它可能会导致麻烦,因为 mail() 函数在 Windows 平台上的实现方式,“to”地址可能会被错误解析。

您应该添加一个Date:标头(它是RFC5322强制性的),如果没有给出,一些邮件客户端可能会假定 1970 年 1 月 1 日作为电子邮件日期(并且它会在所有其他旧邮件之间丢失)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM