这个问题已被反复询问,但似乎没有一个解决方案:
我正在运行这个测试php文件:
<?php
$to = "email@gmail.com";
$subject = "Test";
$message = "This is a test";
$from = "From: email@gmail.com";
if(mail($to, $subject, $message, $from)) {
echo 'Email sent successfully!';
} else {
die('Failure');
}
?>
更改php.ini
中的以下行后:
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
以及sendmail.ini
中的这些行:
smtp_server=smtp.gmail.com
smtp_port=587 ;I've tried 465 but gmail doesn't seem to like to connect to SSL
auth_username=email@gmail.com
auth_password=password
邮件无法发送,调试日志如下:
15-02-21 13:35:59 ** --- MESSAGE BEGIN ---
15-02-21 13:35:59 ** To: email@gmail.com
15-02-21 13:35:59 ** Subject: Test
15-02-21 13:35:59 ** From: email@gmail.com
15-02-21 13:35:59 **
15-02-21 13:35:59 ** This is a test
15-02-21 13:35:59 ** --- MESSAGE END ---
15-02-21 13:36:01 ** Connecting to smtp.gmail.com:587
15-02-21 13:36:02 ** Connected.
15-02-21 13:36:02 << 220 mx.google.com ESMTP z10sm6176887pas.18 - gsmtp<EOL>
15-02-21 13:36:02 >> EHLO Lenovo-PC<EOL>
15-02-21 13:36:02 << 250-mx.google.com at your service, []<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
15-02-21 13:36:02 ** Authenticating as email@gmail.com
15-02-21 13:36:02 >> STARTTLS<EOL>
15-02-21 13:36:02 << 220 2.0.0 Ready to start TLS<EOL>
15-02-21 13:36:02 >> QUIT<EOL>
15-02-21 13:36:02 << bunch of special characters
15-02-21 13:36:02 ** Disconnected.
15-02-21 13:36:02 ** Disconnecting from smtp.gmail.com:587
15-02-21 13:36:02 ** Disconnected.
15-02-21 13:36:02 ** Disconnected.
15-02-21 13:36:02 ** Connection Closed Gracefully.
感谢任何帮助。
答案 0 :(得分:2)
没关系我想出来......在Windows 8中,您需要更改sendmail.exe的兼容模式(以及在管理员中运行):
1)左键单击sendmail.exe并转到属性 2)单击兼容性选项卡,然后单击所有用户的更改设置 3)将兼容模式设置为Windows XP(Service Pack 3) 4)单击复选框以管理员身份运行此progrma
希望能帮到别人。