【发布时间】:2014-11-10 07:31:27
【问题描述】:
我正在尝试从 localhost XAMPP 向 Outlook 邮件发送一些电子邮件,但它只显示“错误”消息。我的代码在 Web 服务器端正常运行。
我使用的是 64 位。我正确地按照说明,如何设置使用 XAMPP 发送电子邮件。
有时会发送电子邮件,但大多数情况下并非如此,而且总是“连接超时”。即使它显示电子邮件“已发送”,我也没有收到任何电子邮件。
如何解决这个问题?
这是 php.ini
SMTP = smtp.live.com
smtp_port = 587
sendmail_from = same email as sendmail.ini
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
发送邮件.ini
smtp_server=smtp.live.com
smtp_port=587
auth_username=outlook email
auth_password=********
force_sender=outlook email
我的邮箱 php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/* Email Detials */
$mail_to = "email";
$from_mail = "email";
$from_name = "title";
$reply_to = "";
$subject = "subj...";
$message_body = "";
/* Attachment File
Attachment location */
$file_name = "filename.xml";
$path = "C:/xampp/htdocs/Email/";
// Read the file content
$file = $path . $file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
/* Set the email header
Generate a boundary */
$boundary = md5(uniqid(time()));
// Email header
$header = "From: " . $from_mail . " \r\n";
$header .= "Reply-To: " . $reply_to . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
// Multipart wraps the Email Content and Attachment
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"" . $boundary . "\"";
$message_body .= "This is a multi-part message in MIME format.\r\n\r\n";
$message_body .= "--" . $boundary . "\r\n";
/* Email content
Content-type can be text/plain or text/html */
$message_body .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message_body .= "Content-Transfer-Encoding: 7bit\r\n";
$message_body .= "\r\n";
$message_body .= "$message_body\r\n";
$message_body .= "--" . $boundary . "\r\n";
/* Attachment
Edit content type for different file extensions */
$message_body .= "Content-Type: application/xml;\r\n";
$message_body .= " name=\"" . $file_name . "\"\r\n";
$message_body .= "Content-Transfer-Encoding: base64\r\n";
$message_body .= "Content-Disposition: attachment;\r\n";
$message_body .= " filename=\"" . $file_name . "\"\r\n";
$message_body .= "\r\n" . $content . "\r\n";
$message_body .= "--" . $boundary . "--\r\n";
// Send email
if (mail($mail_to, $subject, $message_body, $header)) {
echo "Sent";
} else {
echo "Error";
}
【问题讨论】:
-
你的
php.ini应该有SMTP=smtp.live.com,而不是SMTP=smtp:live.com。 -
@isim 我现在改了,但还是有错误