使用 PHP 安全发送多封电子邮件
我正在用 PHP 构建一个网站,允许用户发送邀请电子邮件。他们可以一次发送多份。
我听说使用 PHP 的 mail() 函数是一个糟糕的选择,因为它很容易被标记为垃圾邮件。有什么方法可以设置此脚本,以便电子邮件不会被标记为垃圾邮件吗?
我已经阅读了大量的内容,从我今天读到的内容来看,似乎有几个因素会影响邮件是否被标记为垃圾邮件,包括:电子邮件中使用的词语;电子邮件声称发送的域与实际发送域的比较;标题的格式;以及发送电子邮件的频率。
我们使用的电子邮件地址是 Gmail 应用程序的电子邮件地址。因此,如果我发送的电子邮件不“看起来”是垃圾邮件,我从 Gmail 发送它们,并且我可以限制发送电子邮件的频率(也许每 10 分钟 10 封),那么我应该能够毫无问题地执行此操作,对吧?
编辑
这不是新闻通讯。我是否还需要担心邀请电子邮件被标记为垃圾邮件?
I'm building a website in PHP that allows users to send invitation emails. They are allowed to send more than one at once.
I'm told that using PHP's mail() function is a bad choice because it can easily be marked as spam. Is there some way that I can set up this script so that the emails are not marked as spam?
I've done quite a lot of reading and from what I've read today it seems like a few factors can influence whether mail is marked as spam including: the words used in the emails; the domain that the emails say they are sent from compared to where they actually originate; formatting of headers; and the frequency of emails sent.
The email addresses that we use are with Gmail Apps. So, if the emails I send don't "look" spammy, I send them from Gmail, and I can limit the frequency of the emails sent (maybe 10 every 10 minutes) then I should be able to do this without a problem right?
EDIT
This is not for a newsletter. Do I even have to worry about being marked as spam for invitation emails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然你的结论是正确的,但你的推理并不完全正确。 php 的邮件功能不会导致您的电子邮件被标记为垃圾邮件,因为它发送的电子邮件与其他邮件相同。
php的邮件功能的问题在于它的级别非常低,因此如果您不知道如何正确使用它,并留下电子邮件注入漏洞,人们可以使用您的网站通过它发送垃圾邮件,进而可能将您的服务器作为垃圾邮件来源列入ISP 黑名单。只要您从额外的标头字段(From:等)中删除 \n 和 \r ,您应该是安全的。
另一个问题是您必须将自己的有效标头添加到电子邮件中。
还有一个问题是,每次调用 mail() 时,它都会与您的 smtp 服务器连接和断开连接,尽管我认为有一种方法可以使用一次邮件调用来发送多封电子邮件。但这会很复杂,因为它可能需要查看 rfc282 并弄清楚如何做到这一点。
while your conclusion is correct, your reasoning is not quite right. php's mail function will not cause your emails to be marked as spam, because it sends the same emails as anything else would.
the problem with php's mail function is that it is very low level, and so if you do not know how to use it properly, and leave email injection vulnerabilities, people could use your site to send spam messages through it, and in turn this could get your server blacklisted as a source of spam by isps. as long as you strip \n and \r from your extra header fields (From:, etc), you should be safe.
Another issue is that you have to add your own valid headers to your emails.
Yet another issue is that it would connect and disconnect from your smtp server for each time you call mail(), although I think there is a way you can send multiple emails using one call to mail. this would be complicated though since it would probably involve looking through rfc282 and figuring out how to do it.
首先,您需要为您的域提供有效的 mx.record...
如果您使用邮件功能,您应该发送如下有效标头:
at first you need an valid mx.record for your domain...
if you use the mail function you should send valid headers like these:
您需要使用 SMTP 服务器,然后使用任何 php 库进行连接。这里有一些有用的库和一些示例
you need to use a SMTP server and after that connect using any php library for php. Here you have some useful libraries and some examples as well