如何用php发送邮件而不让邮件自动落入垃圾箱

发布于 2024-10-09 02:33:22 字数 135 浏览 7 评论 0原文

我使用 PHP 的 mail() 函数发送一些电子邮件。但我所有的邮件都会自动进入垃圾箱。有办法防止这种情况吗?如果是这样,我应该在哪里阅读以了解更多信息。

您会推荐我使用 PHPmailer 吗?

最诚挚的问候, 亚历山大

Im using PHP's mail() function to send some emails. But all my mails land automaticly in the trash box. Is there a way of preventing this? If so, where should i read to learn more about it.

Would you recommend me using PHPmailer?

Best of regards,
Alexander

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

在巴黎塔顶看东京樱花 2024-10-16 02:33:22

TL;DR:没有灵丹妙药。仅仅因为您可以学习如何用 PHP 编写电子邮件,并不能保证它会被路由到某人的邮箱,甚至不会被接受。成功是基于声誉,而不是任何单一的修复。

我是(编辑:曾经)一名邮件服务器工程师,编写过 SpamAssassin 规则,并且对发送或接收电子邮件的客户有深入的问题。

收件人的邮件服务器扫描您的电子邮件,查找属性和“历史问题”(缺少邮件代理、来自您的网络服务器 IP 等)。这些获得“积分”。比较总点数,收件人的服务器可能会执行以下一项或多项操作:

  • 列出
  • SMTP 期间拒绝的项目、
  • 路由到垃圾邮件文件夹、
  • 路由到收件箱,但标记为“垃圾邮件
  • 被黑洞(接受了,然后神秘地丢失了)。

“分数”(分数)仅对特定的反垃圾邮件解决方案有意义。没有公开测试。解决所有你能解决的问题,成功就会上升。

*第一个问题是:不要将电子邮件直接发送到收件人的 SMTP 服务器。该网络空间发送 99.9% 的垃圾邮件。扫描电子邮件需要花钱,因此优秀的电子邮件管理员会阻止或拒绝此类连接。

源 IP 的“修复”方法是:使用 SMTP 网关。网关可以是我们的 ISP 邮件服务器,也可以是商业服务。首先检查他们的服务条款。他们可能会禁止使用经过身份验证的网络表单发送电子邮件,因为这些表单经常被滥用(“有人黑了我”不是借口)。

如果您有电子邮件托管,请执行以下操作:创建一个名为 '[电子邮件受保护]'。你喜欢怎么称呼它就怎么称呼它。现在,您希望 PHP 脚本使用经过身份验证的 SMTP 通过该地址发送电子邮件。 我将把学习如何使用 PHP 中的经过身份验证的 SMTP 的过程留给您作为学习练习——网上有很多教程)。

一旦您通过您的有效的 SMTP 服务器,邮件将被视为“源自”您的 SMTP 网关。它不被视为来自您的脚本。但这并不是故事的结束

  1. 正如其他人指出的那样,请确保您没有丢失显示标题,例如收件人:发件人:主题:和日期:。严格来说,这些标头在电子邮件握手中不是“必需的”,但实际上,没有信誉良好的电子邮件软件会忽略它们。此外,日期必须采用标准日期格式,否则某些垃圾邮件过滤器会对其进行标记。

不要将此主题与“信封标头”(SMTP 握手中的隐藏内容)混淆,后者也会影响您的分数。使用 SMTP 网关通常可以解决这个问题(因为收件人的邮件服务器将与您的网关主机握手)。

  1. 您的发件人地址必须有效。不要使用假域名。请勿将您的域名与假邮箱名称一起使用。一些反垃圾邮件软件会执行“发件人验证”来测试发件人地址是否伪造或伪造(过于简单化:他们会尝试发送回复并查看您是否接受)。

第一个错误是将您的发件人地址设置为“[电子邮件受保护]” ,而不是创建该邮箱。当这种情况发生时,每个人对您的电子邮件的“发件人验证”都会失败,您看起来就像一个掩盖其踪迹的垃圾邮件发送者。

  1. 如果您的域 DNS 有 SPF 记录,请 100% 确定它列出了可能为您的域发送电子邮件的每个 IP。这是一个技术主题。拥有有效、正确的 SPF 记录会对您的投递能力有所帮助。但如果您误解并创建了不良(不正确)的 SPF 记录,您的情况将会更糟。使用此功能之前请花点时间了解一下。

  2. 如果您的企业拥有真实地址或邮政信箱,请尽量避免使用“域名注册隐私”或“域名代理”服务。当本文撰写时(2011 年),匿名服务可能会阻止您的邮件或“标记为垃圾邮件”,这在过去确实是事实。如今情况已不再那么真实,但仍然值得考虑。

  3. 了解您的邮件服务器的 IP 地址,并定期检查它是否被列入 SpamCop、SpamHaus 或 Barracuda 垃圾邮件黑名单的“黑名单”。谷歌了解更多。有监控服务和可以向您发出警报的脚本。但如果您出现在这些列表中,则意味着您没有监控到其他事情正在发生......

如上所述,没有简单的答案。 :)

TL;DR: There's no magic bullet. Just because you can learn how to form an email in PHP, does not guarantee it is routed to someone's mailbox, or even accepted. Success is based on reputation, not any single fix.

I am (edit: was) a mail server engineer, have written SpamAssassin rules, and have deep-dived issues for customers sending or receiving email.

The recipient's mail server scans your email, looking for attributes and "historical problems" (lack of mail agent, coming from your webserver IP, etc). These get "points". The total number of points is compared, and the recipient's server may do one or more of the following:

  • List item
  • refused during SMTP,
  • routed to Spam folder,
  • routed to Inbox, but tagged "SPAM"
  • blackholed (accepted, then mysteriously lost).

"Points" (score) only means something to a particular anti-spam solution. There is no public test. Fix ALL the problems you can, and success goes up.

*The #1 issue is: do not send email directly to the recipient's SMTP server. This network space sends 99.9% spam. It costs money to scan email, so a good email admin will block or refuse such connections.

The "fix" for your source IP is: Use an SMTP Gateway. The gateway can be our ISP mailserver, or a commercial service. Check first with their terms of service. They may prohibit sending emails using an authenticated web form, since these are so frequently abused ("someone hacked me" is not an excuse).

If you have email hosting, do the following: create a mailbox called for example '[email protected]'. Call it what you like. Now you want your PHP script to send the email -through- that address, using Authenticated SMTP. I'll leave the process of learning how to use Authenticated SMTP from PHP as a learning exercise for you -- there are many tutorials online).

Once you send emails through your valid SMTP server, the mail is seen as "originating" from your SMTP gateway. It's not seen as coming from your script. But this isn't the end of the story

  1. As someone else noted, Be sure you are not missing display headers such as To: From: Subject: and Date:. Strictly speaking these headers are NOT "required" in email handshaking, but in practical terms no reputable email software omits them. Also, Date must be in the standard date format, or some spam filters will flag it.

This topic is not to be confused with "envelope headers" (the hidden stuff in the SMTP handshaking), which also can also impact your score. Using an SMTP Gateway usually takes care of this (since the recipient's mailserver will handshake with your gateway host).

  1. Your FROM address must be VALID. Do not use a fake domain. Do not use your domain name with a fake mailbox name. Some anti-spam software will do a "Sender Verify" to test if the From address is bogus or fake (oversimplified: they'll try sending a reply and see if you would accept it or not).

The #1 mistake is setting your from address as "[email protected]", and not creating that mailbox. When that happens, everyone's "Sender Verify" on your email fails, and you look like a spammer covering their tracks.

  1. If your domain DNS has an SPF record, be 100% sure it lists every IP that might send email for your domain. This is a technical topic. Having a valid, correct SPF record helps your deliverability a little bit. But if you misunderstand and create a bad (incorrect) SPF record, you will be worse off. Take your time to understand before using this.

  2. If you have a business with a real address or PO box, don't use "Domain Registration Privacy" or "Domain Proxy" services if you can avoid it. When this was written (2011) It used to be very true that anonymizing services could get your mail blocked, or "tagged spam". This is less true today, but it's still worth considering.

  3. Know the IP address of your mailserver, and regularly check that it is not "blacklisted" at SpamCop, SpamHaus, or the Barracuda spam blacklists. Google for more. There are monitoring services, and scripts which can alert you. But if you get on these lists, it means there is something else happening you were not monitoring for...

As said, no simple answer. :)

心如狂蝶 2024-10-16 02:33:22

我想你指的是接收器末端的垃圾箱。所以基本上接收电子邮件服务器将其视为垃圾邮件。如果出现以下情况,就会发生这种情况:

1) 您发送的 IP 已被列入垃圾邮件黑名单(共享主机中经常发生)

2) IP 和域相对较新且未知。

(请注意,很多时候,来自成熟网站的时事通讯最终也会成为垃圾邮件)。

如果是您的专用 IP,则为该 IP 设置 RDNS,以匹配域名很可能会解决问题。另一种常见做法是提醒收件人(如果她在您的网站上订阅)检查他们的垃圾邮件文件夹并将您的电子邮件地址列入其邮件帐户的白名单。

问候,

太平绅士

I suppose you mean thrash box at the receiver's end. So basically the receiving email server is regarding it as spam. This can happen if:

1) The IP you are sending from is already blacklisted for spamming (happens often in shared hosting)

2) The IP and domain are relatively new and unknown.

(Note that many times, newsletters from well established sites also end up in spam).

If its your dedicated IP, then setting RDNS for the IP, to match the domain name will very likely solve the issue. Another usual practice is to alert the receiver (if she is subscribing on your website) to check their thrash/spam folder and whitelist your email address in their mail account.

regards,

JP

影子是时光的心 2024-10-16 02:33:22

JP 的答案部分正确,但也可能是您的电子邮件标头,我从经验中知道,这会将内容发送到垃圾邮件文件夹,请尝试以下操作;

将电子邮件设置为您的域,例如无回复或有效回复。

$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

JP's answer is partly correct but it also could be your header's in the email i know from experience this sends stuff to the spam folder try the following;

set the emails to your domain something like no-reply or a valid reply.

$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
土豪 2024-10-16 02:33:22

这可能与您的邮件客户端和垃圾邮件设置配置有关。尝试在 gmail.com 上开设帐户并在那里发送电子邮件,如果没问题,您就知道这是您的邮件服务器/客户端问题。如果不是,请发布您的 PHP 代码和您收到的电子邮件的完整电子邮件标题。

This probably has something to do with your mail client and spam settings configuration. Try opening account on gmail.com and sending email there, if it's OK you know it is your mail server/client problem. If it's not, post your PHP code and full email headers of the email you've got.

猫卆 2024-10-16 02:33:22

发生这种情况是因为很多时候,标头丢失/如果不存在众所周知的电子邮件服务器域密钥签名,或者类似的情况。如果您已经有一个单独的电子邮件服务器,您应该检查是否可以使用 PHP Pear Mail 包使用您的电子邮件服务器发送电子邮件,而不是直接通过邮件功能发送电子邮件。这就是我觉得方便的地方,因为它更加灵活。

This happens because many a times, headers are missing / if its a well known email server domain key signature is not present, or something like that. If you already have a separate email server, you should check out if you can use the PHP Pear Mail package to send email using your email server, rather than directly via mail function. That's what I find convenient, as its much more flexible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文