我有一个应该通过SMTP从outlook365
和我的普通PEAR
邮件发送优惠券的功能。
我目前正在进行测试,将其发送到我自己的电子邮箱中。当我点击提交时,我收到成功消息"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>");
}
}
答案 0 :(得分:1)
您的邮件可能已传输到服务器但在某处被阻止。这可能是因为奇怪的内容,如
$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设置的标题,但是你使用这个标题作为邮件的主题,这真的很奇怪。我不知道结果会是什么,但它可能只是一些无效的邮件,因此被某些服务器吃掉或阻塞。
除此之外:为什么要尝试构建多部分/混合邮件,其中多部分由单个部分组成?这不是真的错,只是没用。