Bounce Email handling with PHP?

后端 未结 14 1426
爱一瞬间的悲伤
爱一瞬间的悲伤 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:09

    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.

    0 讨论(0)
  • 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<br><br>";
        $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."<br><br>";
                    //WHATEVER HERE TO PROCESS BOUNCE
                }   
            }
            else{
                $msg=imap_fetchbody($inst,$row['msgno'],'1');
                echo "not from my server. could be spam, etc.".$msg."<br><br>";
                //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)); 
    } 
    
    0 讨论(0)
  • 2020-11-28 05:11

    Why not create a bounce@domain.com 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.

    0 讨论(0)
  • 2020-11-28 05:18

    You should look at SwiftMailer. It's completely written in PHP and has support for "bounce" emails. http://swiftmailer.org/

    0 讨论(0)
  • 2020-11-28 05:20

    If you've got a POP3 mailbox set up for bounce@domain.com, you could use a POP3 client script written in PHP to retrieve the messages and check for undeliverable messages.

    0 讨论(0)
  • 2020-11-28 05:21

    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.

    0 讨论(0)
提交回复
热议问题