簡體   English   中英

郵件已發送,未收到郵件-SMTP

[英]Message sent, not receiving mail - SMTP

我有一個功能,可以從outlook365和我的普通PEAR郵件中通過SMTP發送優惠券。

我目前正在測試以將其發送到我自己的電子郵件中。 單擊提交后,我會收到成功消息"Message successfully sent!" 但是,當我檢查電子郵件收件箱時,我什么也沒收到。

有什么我沒有包括或做錯的事嗎?

<?
ini_set("include_path", '/home/busaweb/php:' . ini_get("include_path") );
require_once "Mail.php";
include('Mail/mime.php');
function send_notification_email($coupon, $subject){
$email_from = "coupons@*****.com";
$email_to = "jason@*****.com";
$email_subject = $subject;

// Email Message
// This is an HTML formatted message
$email_html_msg = file_get_contents('email_templates/notification.html', true);
$email_html_msg = str_replace("*|HEADER|*", $subject, $email_html_msg);
$email_html_msg = str_replace("*|COUPON-ID|*", $coupon->id, $email_html_msg);
$email_html_msg = str_replace("*|TYPE|*", $coupon->type, $email_html_msg);
$email_html_msg = str_replace("*|PRODUCT|*", $coupon->product, $email_html_msg);
$email_html_msg = str_replace("*|DESC|*", $coupon->desc, $email_html_msg);
$email_html_msg = str_replace("*|FIRST-NAME|*", $coupon->first_name, $email_html_msg);
$email_html_msg = str_replace("*|LAST-NAME|*", $coupon->last_name, $email_html_msg);
$email_html_msg = str_replace("*|EMAIL|*", $coupon->email, $email_html_msg);
$email_html_msg = str_replace("*|ZIPCODE|*", $coupon->zip, $email_html_msg);
$email_html_msg = str_replace("*|PRODUCTS|*", stripslashes($coupon->products), $email_html_msg);
$email_html_msg = str_replace("*|NEWSLETTER|*", $coupon->newsletter, $email_html_msg);


// start setting up the email header
$headers = "From: ".$email_from;

// create boundary string
// boundary string must be unique using MD5 to generate a pseudo random hash
$random_hash = md5(date('r', time())); 
$mime_boundary = "==Multipart_Boundary_x{$random_hash}x";

// set email header as a multipart/mixed message
// this allows the sending of an attachment combined with the HTML message
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// multipart boundary for the HTML message
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=UTF-8\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_html_msg . "\n\n";

// end the multipart message
$email_message .= "--{$mime_boundary}--\n";

$host = "ssl://smtp.office365.com";
$port = "587";
$username = "coupons@*****.com";
$password = "*****";
$headers = array ('From' => $email_from,   'To' => $email_to,   'Subject' => $headers);
$smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port,  'auth' => true, 'username' => $username, 'password' => $password));
$sendit = $smtp->send($email_to, $headers, $email_message);  
$sendit->SMTPDebug  = 1;
if (PEAR::isError($mail)) {   
echo("<p>" . $mail->getMessage() . "</p>");  
 } 
else {   
echo("<p>Message successfully sent!</p>"); 
 }
 }

您的郵件可能已經傳輸到服務器,但是在某處被阻止。 這可能是因為內容奇怪,例如

$headers = "From: ".$email_from;
...
$headers .= "\nMIME-Version: 1.0\n" .
  "Content-Type: multipart/mixed;\n" .
  " boundary=\"{$mime_boundary}\"";
...
$headers = array ('From' => $email_from,   'To' => $email_to,   'Subject' => $headers);

因此,有效地構造了一個包含From和一些MIME設置的標頭,然后將其用作郵件的主題,這確實很奇怪。 我不知道結果是什么,但是可能只是一些無效的郵件,因此它們之間被某些服務器吞噬或阻止。

除此之外:您為什么要構建一個多部分/混合郵件,其中多部分由一個部分組成? 這不是真的錯誤,只是沒用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM