简体   繁体   中英

XAMPP sendmail won't send mail via Gmail

This question has been asked repeatedly but none seem to have a solution:

I'm running this test php file:

<?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');
}
?>

after changing the following lines in 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"

as well as these lines in 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

Mail fails to send and the debug log is as follows:

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.

Any help is appreciated.

Never mind I figured it out... in Windows 8 you are required to change sendmail.exe's compatibility mode (as well as run it in administrator):

1) left click sendmail.exe and go to properties 2) click compatibility tab then click change settings for all users 3) set compatibility mode to Windows XP (Service Pack 3) 4) click the check box for run this progrma as an administrator

Hope that helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM