[英]Message sent, not receiving mail - SMTP
I have a function that is supposed to send a coupon through SMTP from outlook365
and my normal PEAR
mail. 我有一个功能,可以从
outlook365
和我的普通PEAR
邮件中通过SMTP发送优惠券。
I'm currently doing testing to send it to my own e-mail. 我目前正在测试以将其发送到我自己的电子邮件中。 When I click submit I get the success message
"Message successfully sent!"
单击提交后,我会收到成功消息
"Message successfully sent!"
however when I check my email inbox I receive nothing. 但是,当我检查电子邮件收件箱时,我什么也没收到。
Is there something I am not including or doing wrong? 有什么我没有包括或做错的事吗?
<?
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>");
}
}
Your mail might have been transmitted to the server but then got blocked somewhere. 您的邮件可能已经传输到服务器,但是在某处被阻止。 This might be because of strange content, like
这可能是因为内容奇怪,例如
$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);
Thus effectively you construct a header containing From and some MIME setup but then you use this header as the subject of the mail which is really strange. 因此,有效地构造了一个包含From和一些MIME设置的标头,然后将其用作邮件的主题,这确实很奇怪。 I don't know what the result will be but it might simply be some invalid mail which therefore gets eaten or blocked by some server in between.
我不知道结果是什么,但是可能只是一些无效的邮件,因此它们之间被某些服务器吞噬或阻止。
Apart from that: why are you trying to construct a multipart/mixed mail, where the multipart consists of a single part? 除此之外:您为什么要构建一个多部分/混合邮件,其中多部分由一个部分组成? It's not really wrong, only useless.
这不是真的错误,只是没用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.