我想通過PHP函數mail()發送電子郵件時彈出電子郵件?什麼是最好的方法來捕捉?如何在PHP中捕捉退回的電子郵件?
0
A
回答
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";
}
比你只是檢查反彈錯誤郵件的收件箱。下面的示例代碼將連接到一個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);
0
在電子郵件標題中添加退回電子郵件地址,並監視來自PHP的該電子郵件帳戶以進行退回。
+0
對不起,我沒有得到它,你可以請用例子代碼寫下,謝謝提前... –
相關問題
- 1. PHP/DNS捕捉所有電子郵件
- 2. 捕捉RuntimeExceptions,並通過電子郵件
- 3. 捕捉非JIRA電子郵件ID
- 4. 如何檢測退回電子郵件
- 5. 在ASP.NET中捕捉反彈的電子郵件#
- 6. 電子郵件營銷經理如何報告退回的電子郵件?
- 7. 如何在PHPMailer中設置回退純文本電子郵件?
- 8. 退回的電子郵件解析
- 9. 解析退回的電子郵件
- 10. 如何檢查導軌中退回的電子郵件?
- 11. python腳本發送電子郵件,如何捕捉並顯示錯誤發送電子郵件?
- 12. 如何捕捉後退按鈕事件?
- 13. 如何捕獲電子郵件
- 14. 如何在SalesForce電子郵件回覆中包含用戶的電子郵件?
- 15. 如何檢查電子郵件的退回?
- 16. 我如何跟蹤退回的電子郵件?
- 17. 如何處理退回的電子郵件?
- 18. 通過PHP捕獲彈回的電子郵件地址
- 19. PhP電子郵件自動回覆電子郵件
- 20. 如何捕捉PHP中的exit()事件?
- 21. PHP郵件$電子郵件= $ _ POST [ '電子郵件']在$收件人
- 22. 如何在html電子郵件中發送電子郵件回覆或轉發?
- 23. 捕捉MailApp.send電子郵件傳遞失敗
- 24. 優化正則表達式來捕捉電子郵件簽名
- 25. 如何檢查電子郵件在PHP?
- 26. 如何捕捉在PHP
- 27. 在PHP中的電子郵件附件?
- 28. 如何發送電子郵件至選定的電子郵件在PHP
- 29. 在Python中捕獲電子郵件回覆消息
- 30. 在PHP中捕獲HTML表單數組電子郵件
的可能重複http://stackoverflow.com/questions/1011714/bounce-email-handling-with-php –
看看我的代碼示例編輯解決方案 – Gadoma