使用 PHP 处理退回邮件?
这是我的情况:
我有 2 个电子邮件帐户: [email protected] 和[电子邮件受保护]。
我想使用 [email protected] 向所有用户发送电子邮件,但随后“回复”[电子邮件受保护](直到这里,我的 PHP 脚本可以处理它)。
如果电子邮件无法发送,则会发送至 [电子邮件受保护],错误消息可能是 553(不存在的电子邮件...)等。
我的问题是:如何将所有这些退回电子邮件(无法发送电子邮件)定向到 [email protected] 通过处理脚本检查退回错误代码?
我应该使用什么编程语言来“处理脚本”?
“处理脚本”会是什么样子? 你能给一个样品吗?
换句话说:
我应该遵循哪些程序来处理退回电子邮件?
Here is my scenario:
I have 2 email accounts: [email protected] and [email protected].
I want to send email to all my users with [email protected] but then "reply to" [email protected] (until here, my PHP script can handle it).
When, the email can't be sent, it's sent to [email protected], the error message could be 553 (non existent email ...) etc.
My question is: How do I direct all those bounce emails (couldn't-sent emails) to [email protected] through a handling script to check for the bounce error codes?
What programming language should I be using for the "handling script"?
What would the "handling script" look like? Can you give a sample?
in other words:
What are the procedures I should follow to handle the bounce email ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
最好的场景是能够对弹跳类型进行分类:软弹跳、硬弹跳……
我们使用的是 BounceStudio 。 您需要编译它并添加 php 库...一点也不难。 您就拥有该产品的免费和付费版本
一旦我们检测到 某种退回 我们使用 PEAR::MAIL::MIME 来搜索我们之前添加到电子邮件中的自定义标头,可以说:
在此这样我们就可以知道我们发送电子邮件的真正收件人。
希望这对你有帮助! 这样你就可以帮助我获得 500 分 :P
The best scenario is be able to classify the type of bounce: soft, hard...
what we use is BounceStudio. You need to compile it and add the php libraries... not hard at all. You have the free and paid version of that product
once we detect the kind of bounce we use PEAR::MAIL::MIME to search for custom headers that we added previously to the email, lets say:
in this way we can know the real recipient that we sent the email to.
hope this help you! so you can help me to get to the 500 points :P
为什么不创建一个 [email protected] 并使用 php 来 阅读这些电子邮件并做你想做的事?
在发表评论后编辑:请检查我的链接,其中有一个 php 脚本,它将教您如何使用 php 打开电子邮箱并阅读电子邮件。 您可以使用此脚本来检查错误消息。
Why not create a [email protected] and use php to read those emails and do what ever you want?
Edit After your comment : Please chec my link whcih has a php script which will teach you how to open and email box using php and read the emails. You can use this scrip to check the error messages.
让电子邮件退回到一个真正的电子邮件地址(带有登录详细信息等)。
制作一个每 x 分钟运行一次的 php 脚本(例如使用 cron 作业)。 该 php 脚本必须执行以下操作。
- 从邮箱中检索所有电子邮件(例如使用 Zend Mail )
- 检查消息中的错误(例如通过使用正则表达式搜索)
- 做必要的事情。
如果您想具体了解谁退回了,您可以使用用户特定的退回地址。 (例如,请参阅此网站)
Let the emails bounce to an address that is really an emailadress (with login details etc.).
Make a php script which runs ever x minutes (for example with a cron job). This php script must do the following.
- Retrieve all email from the box (use for example Zend Mail)
- Check for the error in the message (e.g. by searching it with regular expressions)
- Do what ever is necessary.
If you want to know specifically who has bounced back you can use user specific bounce addresses. (See for example this site)
也许现在得到答案有点晚了,但你总是可以尝试一些新的东西。
上周我有一个这样的任务,并使用了 Chris Fortune 的 BOUNCE HANDLER 类,它将反弹分成关联数组 - http://www.phpclasses.org/browse/file/11665.html
这将在你用一些邮件程序连接到 POP3 并从中获取退回邮件后使用,然后以此将其解析为碎片,如果具有您搜索的状态,请执行必要的操作。
干杯。
Maybe it's a little late for the answer, but you can always try something new.
I had the last week a task like this, and used BOUNCE HANDLER Class, by Chris Fortune, which chops up the bounce into associative arrays - http://www.phpclasses.org/browse/file/11665.html
This will be used after you connect to the POP3 with some mailer to get the bounces from it, then parse it into pieces with this, and if has the status you searched for, do the necessary actions.
Cheers.
如果您已设置 POP3 邮箱
[电子邮件受保护]
,您可以使用 PHP 编写的 POP3 客户端脚本来检索邮件并检查是否有无法送达的邮件。If you've got a POP3 mailbox set up for
[email protected]
, you could use a POP3 client script written in PHP to retrieve the messages and check for undeliverable messages.您可以使用 imap_open 从 PHP 访问您的邮件。
此功能也适用于 POP3,但并非所有功能都适用。 不过我想 2018 年大多数电子邮件客户端应该支持 IMAP。
这是一个小例子,如何迭代您的电子邮件:
就我而言,我知道我总是从
[电子邮件受保护]
。 所以我可以识别这样的反弹:你说:
因此,如果您的退回电子邮件的主题为“邮件发送失败:错误 553”,那么您可以通过主题来识别它们,如下所示:
失败的电子邮件地址不在header,因此您需要使用一些智能代码从
$message
变量中解析它。You can use imap_open to access your mails from PHP.
This functions also works for POP3 but not every function may work here. However I guess in 2018 most email-clients should support IMAP.
Here is a little example, how to iterate through your emails:
In my case, I know that I always get my mail delivery failed from
[email protected]
. So I could identify bounces like that:You said:
So if your bounce emails have the subject "Mail delivery failed: Error 553" then you could identify them by the subject like this:
The failed email address is not in the header, so you need to parse it from the
$message
variable with some smart code.您始终可以使用 http://cloudmailin.com 之类的内容通过 http 将退回的电子邮件转发到您的 php 服务器,但是您可以使用专门用于发送电子邮件并使用其 api 检索退回邮件详细信息的服务可能会更好。
You could always use something like http://cloudmailin.com to forward the bounced emails on to your php server via http however you may be better with a service dedicated to sending emails and using their api to retrieve the bounce details.
我在寻找 PHP 解决方案时运气很差,但我遇到了这个产品,它能满足我的需要。
它作为本地应用程序 mac/win 运行,但它完成了工作。
http://www.maxprog.com/site/software /internet-marketing/email-bounce-handler_sheet_us.php
i have had pretty bad luck looking for a PHP solution for this, but i ran across this product that does just what i needed.
it runs as a native app mac/win but it does the job.
http://www.maxprog.com/site/software/internet-marketing/email-bounce-handler_sheet_us.php
我正在寻找同一问题的答案。 问题的部分更多,选项也更多。
为了处理退回的电子邮件,我找到了 PHP 类,纯粹用 PHP 编写,如果您有 PHP 驱动的站点,则无需编译或安装其他软件。 这是非常容易使用。
如果您使用 cPanel 或 InterWorx/SiteWorx,您可以配置一些地址以使用脚本(例如 PHP 脚本)处理收到的电子邮件,这样您就可以借助上述类编写自己的处理。 当然,您仍然可以创建普通电子邮件帐户并通过 POP3 或 IMAP 检索邮件,然后解释它们。 我认为第一个更好,因为它是直接的,您不必使用额外的渠道,例如 IMAP。 当然,如果您无法配置邮件服务器,或者不知道如何配置,那么前者更适合您。
祝你好运! :)
I was searching for the answer to the same question. There are more parts of the question, and more options.
For handling the bounced e-mail, I found a PHP class, purely in PHP, no compile or additional software installation needed if you have a PHP powered site. It is very easy to use.
If you are using cPanel, or InterWorx/SiteWorx, you can configure some of the addresses to handle the received e-mails with a script, for example a PHP script, so you can write your own handling with the aid of the mentioned class. Or of course still you can create ordinary e-mail accounts and retrieve the mails via POP3 or IMAP, and then interpret them. I think the first one is better, because it's direct, you don't have to use additional channels, like IMAP. Of course if you can't configure your mail server, or don't know how to do it, then the former is better for you.
Good luck! :)
在 php 邮件命令 http://php.net/mail 中,
使用第五个参数并添加“-f”到它。
因此,您使用“-f [email protected]”作为
参数phpList 时事通讯管理器 使用它来管理退回邮件。
一旦邮箱中的退回邮件填满,您就可以将其弹出并进行处理。 这是处理它们的最简单方法,而不是在它们到达时处理它们。
In the php mail command http://php.net/mail
you use the fifth parameter and add "-f" to it.
So, you use "-f [email protected]" as the parameter
the phpList newsletter manager uses this to manage bounces.
Once the bounces fill up in the mailbox, you can POP them, and process them. That's the easiest way to deal with them, as opposed to handling them when they arrive.
这是使用 IMAP 处理退回邮件的固定解决方案。
我将 Mail 实例的 Return-Path 标头更改为专用的 [email protected]
我认为唯一可行的简单方法是以下方法,它通过 POP3 检查专用收件箱,并可以根据收到的消息处理每封电子邮件。
Here is a canned solution to process bounces using IMAP.
I changed the Return-Path header of my Mail instance to a dedicated [email protected]
The only method easy enough for me to consider viable is the following, which checks via POP3 the dedicated inbox and can handle each email based on the message received.
我们正在使用 Procmail 来过滤此类邮件。 在检查了此处已经提到的一些解决方案之后,我们最终得到了一个简单的 Procmail 配方来检测退回邮件。 根据您需要的准确性,这可能适用于您的情况。
有关详细信息,请查看此博客条目。
We are using Procmail to filter these kind of mails. After examining some of the solutions already mentioned here, we ended up with a simple Procmail recipe to detect bounce messages. Depending on the accuracy you need, this might be applicable to your situation.
For details, check this blog entry.
我有同样的问题,确切的情况。 默认情况下,我的邮件服务器将所有返回的邮件发送到最初发送邮件的同一帐户,并自动发送消息“邮件发送失败:将消息返回给发件人”。
我真的不想知道为什么它被退回,有这么多的邮件交易,我只想删除坏的。 没有时间检查特定规则,例如不存在、不可用等,,,只想标记删除并继续。
退回邮件非常琐碎,因为您需要处理许多不同的服务器和响应类型。 每个反垃圾邮件软件或操作系统方案都可以在退回的电子邮件中发送不同的错误代码。
我建议您阅读并下载来自 KIDMOSES 的处理退回邮件 - 使用 PHPMAILER-BMH 和 AUTHSMTP 的已修复调试版本 http://www.kidmoses.com/blog-article.php?bid=40 如果您想设置 IMAP 并发送您自己的自定义标头,将它们发送到您的[电子邮件受保护] 并然后祈祷脚本是否捕获您发送的退回邮件中写入的标头。 我试过了,有效。
但如果您想遵循我的快速简单的解决方案来解决我的问题,这就是秘密。
1 - 从 KIDMOSES 网站或我的网站下载更好的版本,以防万一 KIDMOSES 想要搬到其他地方 http://chasqui.market/downloads/KIDMOSES-phpmailer-bmh.zip
2 - 包含返回邮件文本的变量是 $body,它本身包含错误的返回电子邮件(所以它是一个多维的大批 )。 (还包含您的服务器邮件和其他 DNS 邮件内容,但我们正在寻找退回的坏邮件。3
- 由于您自己的服务正在向您发送退回的电子邮件,因此它不太可能更改其格式和自己的标头,发送回退回的电子邮件,因此您可以安全地选择退回的电子邮件数组的顺序,在我的情况下始终是相同的格式模板(除非您更改系统或提供商)
4 - 我们会调查该 $body。并搜索所有电子邮件字符串变量并将它们提取到名为 $matches 的二维数组中
5 - 我们通过使用 打印数组来选择数组位置print_r( array_values( $matches ));
6 - 这是您需要修改的代码,位于 class.phpmailer-bmh.php 文件的第 500 行左右,
因此我们忘记了返回的内容。您可以对它们进行优化,也可以对它们进行 MySQL 处理,或者对它们进行处理
重要 。
注释示例目录中的callback_echo.php 中的回声,否则在打印之前您会得到所有垃圾。
我的输出
I had the same problem, exact situation. By default my mail server, is sending all my returned mails to the same account that it was originally sent from, with automatic msg "Mail delivery failed: returning message to sender".
I dont really want to know why it was returned, had so many mails transactions that I just want to remove the bad ones. Dont have time to check specific rule such as Doestn Exist, Unavailable, etc ,,, Just want to flag for deletion and go on.
Bounce mails are so trivial as you need to deal with a lot of different servers and responses types. Each anti spam software or operating system scenario can send a different error code with the bounced email.
I recomend you to read and download this fixed debugged version of Handling Bounced Email - USING PHPMAILER-BMH AND AUTHSMTP from KIDMOSES here http://www.kidmoses.com/blog-article.php?bid=40 if you want to setup IMAP and and send your own custom headers, send them to your [email protected] and then cross your fingers to see if the script catches the headers you sent written in the bounced mail. I tried it, works.
But if you want to follow my quick and easy fix that resolved my problem, here is the secret.
1 - Download the better version from KIDMOSES site or from my site, just in case KIDMOSES want to move somewhere else http://chasqui.market/downloads/KIDMOSES-phpmailer-bmh.zip
2 - The variable that contains the text of your returned mail is $body and itself contains the bad returned email (SO ITS AN MULTIDIMENSIONAL ARRAY ). (Also contains your servers mail and other DNS mails stuff, but we are looking for the BAD MAIL BOUNCED.
3 - Since your OWN SERVICE is sending you back the bounced email, then its not likely to change its format and own headers, sending back bounced emails, so you are safe to pick the order of bounced email array returned. In my case was always the same format template. (Unless you change systems or providers)
4 - We look into that $body and search for all email string variables and extract them positioning them into a two dimensional array called $matches
5 - We select the array position, by printing the array using print_r( array_values( $matches ));
6 - This is the code that you need to modify. Its around line 500 from class.phpmailer-bmh.php file
So we forget about returned headers and concentrate on the bad emails. You can excel them, you can MySQL them, or process to whatever you want to do.
IMPORTANT
Comment the echos in callback_echo.php in the samples directory otherwise you get all the junk before printed.
MY OUTPUT
你应该看看 SwiftMailer。 它完全用 PHP 编写,并支持“退回”电子邮件。
http://swiftmailer.org/
You should look at SwiftMailer. It's completely written in PHP and has support for "bounce" emails.
http://swiftmailer.org/