正确使用电子邮件 FROM 标头
我想让用户通过向朋友发送电子邮件来共享我网站上的信息。在我深入之前,我想确保我不会因为做错事而被列入黑名单。
如果我的域名是 example.com,我可以将邮件 FROM 标头设置为用户提供的电子邮件地址吗?
例如,我想与我的朋友 Bob 共享 example.com 上的页面。 Bob 的电子邮件地址是 [email protected],我的电子邮件地址是 [电子邮件受保护]。当 example.com 向 Bob 发送电子邮件时([电子邮件受保护])将设置 FROM 到我的电子邮件([电子邮件受保护])。
这是一个问题吗,因为电子邮件是从 example.com 发送的,但 FROM 标头包含除自身以外的域?
以下将从 example.com 发送
$to = '[email protected]';
$subject = 'Some subject';
$msg = 'Some message';
$headers = 'From: [email protected] <[email protected]>' . "\n\r";
mail( $to, $subject, $msg, $headers );
或者我需要执行如下操作吗?
$headers = 'From: [email protected] <[email protected]>' . "\n\r";
任何和所有的帮助将不胜感激。
I want to let users share information on my site by sending an email to a friend. Before I go to far I want to make sure I won't get blacklisted for doing something incorrectly.
If my domain is example.com can I set the mail FROM header to the email address supplied by the user?
For example, I want to share a page at example.com with my friend Bob. Bob's email address is [email protected] and my email address is [email protected]. When example.com sends an email to Bob([email protected]) it will set FROM to my email([email protected]).
Is this an issue since the email is being sent from example.com but the FROM header contains a domain other than itself?
The following would be sending from example.com
$to = '[email protected]';
$subject = 'Some subject';
$msg = 'Some message';
$headers = 'From: [email protected] <[email protected]>' . "\n\r";
mail( $to, $subject, $msg, $headers );
Or do I need to do something like the following?
$headers = 'From: [email protected] <[email protected]>' . "\n\r";
Any and all help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有多个电子邮件标头可以指示谁“发送”电子邮件以及回复谁。可以在 讨论 FormMail 如何处理事务的页面上找到该概念的相当不错的休闲文章。
听起来您可能想要的是:
There are multiple email headers that give some indication of who "sent" an email and who to reply to. A fairly good, casual writeup of the concept can be found on the page discussing how FormMail handles things.
It sounds like what you might want is:
您在 from 标头中写入的内容并不相关。重要的是,您使用来自您的域的信封发件人地址。例如,这是根据 SPF 检查的。如果您希望收件人能够回复[电子邮件受保护],您还需要添加回复标头。
What you write in the from header isn't that relevant. Important is that you you use an envelope sender address from your domain. This is checked against SPF for example. If you want the recipient to be able to reply to [email protected] you need to add a reply-to header as well.
不,设置哪个
From:
标头电子邮件并不重要为什么您不尝试一下?
No, it really DOESN't matter which
From:
header email has been setWhy didn't you try it?
许多(如果不是大多数)电子邮件服务器都没有注册特定域,更大的问题是您的服务器是否正确识别自身(拥有反向查找条目可以帮助)并确保它没有被列入黑名单。您可以使用以下服务进行检查:http://www.dnsbl.info/。
大多数具有动态 IP 的主机都被认为是可疑的,但即使是专用 VPS 也可以列出,因此值得检查。您还应该按照其他一些响应中的概述正确设置标题格式。如果这是针对关键应用程序(例如,您向人们收费并且他们希望收到邮件),您应该考虑使用第 3 方 SMTP,它应该负责确保您不会被列入黑名单。
Many, if not most, email servers are not registered for a specific domain, the bigger issue is if your server correctly identifies itself (having a reverse lookup entry can help) and make sure it's not blacklisted. You can use a service like: http://www.dnsbl.info/ to check.
Most hosts with dynamic IPs are considered suspect, but even a dedicated VPS can be listed, so it's worth checking. You should also correctly format the headers as outlined in some of the other responses. If this is for a critical application (e.g., you are charging people and they expect to get mail), you should consider a 3rd-party SMTP which should take care of making sure you don't get blacklisted.