从POP3帐户中删除无法送达的电子邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从POP3帐户中删除无法送达的电子邮件相关的知识,希望对你有一定的参考价值。
You can set this as a cron to automatically clean up unsubscribes after sending out a mass email.
// include class // initialize object $pop3 = new Net_POP3(); // attempt connection to server if (!$pop3->connect("mail.yourserver.com", 110)) { } // attempt login $ret = $pop3->login($email_login, $email_password); } // print number of messages found echo $pop3->numMsg() . " message(s) in mailbox "; // print message headers if ($pop3->numMsg() > 0) { for ($x=1; $x<=$pop3->numMsg(); $x++) { // for ($x=1; $x<=10; $x++) { $hdrs = $pop3->getParsedHeaders($x); if ( preg_match( '/MAILER-DAEMON/i', $hdrs['From'] ) || preg_match( '/Mail Administrator/i', $hdrs['From'] ) || preg_match( '/Returned mail/i', $hdrs['Subject'] ) || preg_match( '/User Unknown/i', $hdrs['Subject'] ) ) { // extract the email address from the body $mail_body = $pop3->getBody($x); $pattern = '/[A-Za-z0-9_-][email protected][A-Za-z0-9_-]+.([A-Za-z0-9_-][A-Za-z0-9_]+)/'; //regex for pattern of e-mail address $undeliverable_email = $matches[0]; echo "<b>Remove " . $undeliverable_email . "</b><br/><br/>"; // add to database table 'bad_emails' to prevent future mailings to this address } // delete the message $pop3->deleteMsg($x); } } } // disconnect from server $pop3->disconnect();
以上是关于从POP3帐户中删除无法送达的电子邮件的主要内容,如果未能解决你的问题,请参考以下文章