使用 PHP 发送邮件时如何删除“via”和服务器名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8236312/
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
How to remove "via" and server name when sending mails with PHP?
提问by lisovaccaro
When I send a mail with PHP the destinatary gets a header like this one:
当我用 PHP 发送邮件时,destinatary 会得到一个这样的标题:
[email protected] **via** de p3nlhg147.shr.prod.phx3.secureserver.net
I want to remove the "via" part. Most automated mails from websites don't have the "via" so it's certainly possible to remove it.
我想删除“通过”部分。大多数来自网站的自动邮件都没有“via”,因此当然可以将其删除。
How do they do it?
他们是怎么做到的呢?
回答by richard
Yes, you can get rid the "via" part. Here's the details:
是的,您可以摆脱“通过”部分。以下是详细信息:
1) SPF and DKIM
Firstly, you would need to set an SPFrecord for the domain you are sending emails from and enable DKIMas well. These are primarily for identifying your messages against spam.
首先,您需要为发送电子邮件的域设置SPF记录并启用DKIM。这些主要用于识别您的邮件是否为垃圾邮件。
2) "From: [email protected]"
Secondly, make sure you are setting the “From: ” header to be an email address on the domain you are sending messages from. Don't pretend to be someone else. Use “From: [email protected]” if you are sending the messages from abc.com, rather than anything else, such as [email protected], or [email protected], or whatever. If you want the recipient to reply to your Gmail email instead of your domain email, use the “Reply-To: ” header. “From: ” must always be the domain email that you are sending the email from.
其次,确保您将“发件人:”标题设置为您发送邮件的域上的电子邮件地址。不要假装是别人。如果您从 abc.com 发送消息,请使用“发件人:[email protected]”,而不是其他任何内容,例如 [email protected] 或 [email protected] 或其他任何内容。如果您希望收件人回复您的 Gmail 电子邮件而不是域电子邮件,请使用“回复:”标题。“发件人:”必须始终是您发送电子邮件的域电子邮件。
3) "Return-Path: [email protected]"
Thirdly and most importantly, set the “Return-Path: ” header to be the same domain as that of the “From: ” header. Use the 5th parameter of the mail() function for this:
第三,也是最重要的一点,将“Return-Path:”标头设置为与“From:”标头的域相同。为此使用 mail() 函数的第 5 个参数:
mail('[email protected]', 'Subject', "Message Body", $headers, '[email protected]')
So the Return-Path of this message would be “[email protected]” (the email address immediately following the -f switch). The $headers parameter should contain all the necessary message headers. Make sure “From: ” is [email protected].
因此,此消息的返回路径将是“[email protected]”(紧跟在 -f 开关之后的电子邮件地址)。$headers 参数应该包含所有必要的消息头。确保“发件人:”是 [email protected]。
After these steps and measures, Gmail should now completely trust your messages from yourdomain.com. The ‘via‘ field of your messages should be gone and the ‘mailed-by‘ field as well as the ‘signed-by‘ field should be correctly showing up as yourdomain.com.
完成这些步骤和措施后,Gmail 现在应该完全信任您来自 yourdomain.com 的邮件。邮件的“via”字段应该消失,“mailed-by”字段和“signed-by”字段应该正确显示为 yourdomain.com。
Hope it helps!
希望能帮助到你!
回答by Mujibur
I also fetched the same problem. But I have overcome the problem by using the following code:
我也遇到了同样的问题。但是我通过使用以下代码克服了这个问题:
mail('[email protected]', 'the subject', 'the message', null,'[email protected]');
Make sure that last parameter is -f with the email address.
确保最后一个参数是带有电子邮件地址的 -f。
You can add the
您可以添加
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";<br />
mail('[email protected]', 'the subject', 'the message body in html format', $headers,'[email protected]');
for the html message body in email.
用于电子邮件中的 html 消息正文。
回答by Kaszoni Ferencz
See what Google says about this here: http://support.google.com/mail/bin/answer.py?hl=en&ctx=mail&answer=1311182
在此处查看 Google 对此有何评论:http: //support.google.com/mail/bin/answer.py?hl=en&ctx=mail&answer=1311182
All the best!
祝一切顺利!
回答by AndreKR
This is probably added by your MTA and you didn't say which MTA you are using.
这可能是由您的 MTA 添加的,而您没有说明您使用的是哪个 MTA。
I'd recommend sending the mails not by PHP's mail()
function but via SMTP, possibly even with SMTP-Auth, using something like PHPMailer.
我建议不是通过 PHP 的mail()
功能而是通过 SMTP发送邮件,甚至可能使用 SMTP-Auth,使用类似PHPMailer 的东西。
回答by Umesh Gaire
@Mujibur is also right, But I used. But Didn't missed Headers too.
@Mujibur 也是对的,但我用过。但也没有错过标题。
mail($to, $subject, $message, $headers, '-f'.$from_email_address);
And its successful to me, Let's check it from your side.
它对我来说是成功的,让我们从你身边检查一下。