2014-01-08 36 views

回答

7

首先,您需要使用附加標題發送帶有mail()函數的電子郵件。您將退回電子郵件地址指向您將收集退回電子郵件的郵箱。下面的代碼是一個如何實現這個目標的例子。

$recipient = "[email protected]"; 
$subject = "test subject"; 
$message = "test message"; 

$body = "<html>\r\n"; 
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\r\n"; 
$body .= $message; 
$body .= "</body>\r\n"; 
$body .= "</html>\r\n"; 

$headers = "From: My site<[email protected]>\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "Return-Path: [email protected]\r\n"; 
$headers .= "X-Mailer: PHP\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

$result = mail($recipient, $subject, $body, $headers); 

if($result) 
{ 
    echo "email sent"; 
} 
else 
{ 
    echo "email send error"; 
} 

SOURCE

比你只是檢查反彈錯誤郵件的收件箱。下面的示例代碼將連接到一個imap收件箱,獲取並打印出它在其中找到的所有電子郵件。您可以輕鬆地根據您的需求定製它。

/* connect to server */ 
$hostname = '{example.com:143}INBOX'; 
$username = '[email protected]'; 
$password = 'password'; 

/* try to connect */ 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to mailbox: ' . imap_last_error()); 

/* grab emails */ 
$emails = imap_search($inbox,'ALL'); 


/* if emails are returned, cycle through each... */ 
if($emails) { 

    /* begin output var */ 
    $output = ''; 

    /* put the newest emails on top */ 
    rsort($emails); 

    /* for every email... */ 
    foreach($emails as $email_number) { 

    /* get information specific to this email */ 
    $overview = imap_fetch_overview($inbox,$email_number,0); 
    $message = imap_fetchbody($inbox,$email_number,1.2); 

    /* output the email header information */ 
    $output.= '<div '.($overview[0]->seen ? 'read' : 'unread').'">'; 
    $output.= '<span>'.$overview[0]->subject.'</span> '; 
    $output.= '<span>'.$overview[0]->from.'</span>'; 
    $output.= '<span>'.$overview[0]->date.'</span>'; 
    $output.= '</div>'; 

    /* output the email body */ 
    $output.= '<div class="body">'.$message.'</div>'; 
    } 

    echo $output; 
} 

/* close the connection */ 
imap_close($inbox); 

SOURCE

0

在電子郵件標題中添加退回電子郵件地址,並監視來自PHP的該電子郵件帳戶以進行退回。

+0

對不起,我沒有得到它,你可以請用例子代碼寫下,謝謝提前... –