Bounce Email handling with PHP?

后端 未结 14 1502
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 04:30

Here is my scenario:

I have 2 email accounts: admin@domain.com and bounce@domain.com.

I want to send email to all my users with admin@domain.com but then \"r

14条回答
  •  隐瞒了意图╮
    2020-11-28 05:10

    Here is a canned solution to process bounces using IMAP.

    I changed the Return-Path header of my Mail instance to a dedicated bounce@xxxxxx.us

    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.

    $inst=pop3_login('mail.xxxxxx.us','110','bounce@xxxxxx.us','pass');
    $stat=pop3_stat($inst);
    //print_r($stat);
    if($stat['Unread']>0){
        echo "begin process

    "; $list=pop3_list($inst); //print_r($list); foreach($list as $row){ if(strpos($row['from'],'MAILER-DAEMON')!==FALSE){ $msg=imap_fetchbody($inst,$row['msgno'],'1'); if(strpos($msg,'550')!==FALSE){ echo "handle hard bounce".$msg."

    "; //WHATEVER HERE TO PROCESS BOUNCE } } else{ $msg=imap_fetchbody($inst,$row['msgno'],'1'); echo "not from my server. could be spam, etc.".$msg."

    "; //PROBABLY NO ACTION IS NEEDED } //AFTER PROCESSING //imap_delete ( resource $imap_stream , int $msg_number [, int $options = 0 ] ) //commented out because I havent implemented yet. see IMAP documentation } } else{ echo "no unread messages"; } //imap_close ( resource $imap_stream [, int $flag = 0 ] ) //commented out because I havent implemented yet. see IMAP documentation. //flag: If set to CL_EXPUNGE, the function will silently expunge the mailbox before closing, removing all messages marked for deletion. You can achieve the same thing by using imap_expunge() function pop3_login($host,$port,$user,$pass,$folder="INBOX",$ssl=false) { $ssl=($ssl==false)?"/novalidate-cert":""; return (imap_open("{"."$host:$port/pop3$ssl"."}$folder",$user,$pass)); } function pop3_stat($connection) { $check = imap_mailboxmsginfo($connection); return ((array)$check); } function pop3_list($connection,$message="") { if ($message) { $range=$message; } else { $MC = imap_check($connection); $range = "1:".$MC->Nmsgs; } $response = imap_fetch_overview($connection,$range); foreach ($response as $msg) $result[$msg->msgno]=(array)$msg; return $result; } function pop3_retr($connection,$message) { return(imap_fetchheader($connection,$message,FT_PREFETCHTEXT)); } function pop3_dele($connection,$message) { return(imap_delete($connection,$message)); }

提交回复
热议问题