I am trying to send emails from my gmail account using php (xampp). I search over stackoverflow and as I got the things I changed my xampp's files sendmail.ini and php.ini as,
In C:\xampp\php\php.ini I removed the semicolon from the beginning of the line extension=php_openssl.dll
to make SSL working for gmail for localhost.
in php.ini file under [mail function] I changed
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = mukul.agrawal19@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Then in C:\xampp\sendmail\sendmail.ini. I replaced all the existing code in sendmail.ini with following code
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mukul.agrawal19@gmail.com
auth_password=my-gmail-password
force_sender=mukul.agrawal19@gmail.com
then I wrote a simple mail function
<?php
$to = 'mukulagrawal13@live.com';
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
then went on the this page by my browser, got echo as Mail Failed.
I saw my debug file and I got
14/12/03 18:24:00 ** --- MESSAGE BEGIN ---
14/12/03 18:24:00 ** To: mukulagrawal13@live.com
14/12/03 18:24:00 ** Subject: Test email
14/12/03 18:24:00 ** From:mukul.agrawal19@gmail.com
14/12/03 18:24:00 ** Reply-To:mukul.agrawal19@gmail.com
14/12/03 18:24:00 **
14/12/03 18:24:00 ** Hello World!
14/12/03 18:24:00 **
14/12/03 18:24:00 ** This is my first mail.
14/12/03 18:24:00 ** --- MESSAGE END ---
14/12/03 18:24:01 ** Connecting to smtp.gmail.com:25
14/12/03 18:24:08 ** Connected.
14/12/03 18:24:08 << 220 mx.google.com ESMTP o17sm23150442pdn.33 - gsmtp<EOL>
14/12/03 18:24:08 >> EHLO Mukul-PC<EOL>
14/12/03 18:24:10 << 250-mx.google.com at your service, [223.186.182.29]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
14/12/03 18:24:10 ** Authenticating as mukul.agrawal19@gmail.com
14/12/03 18:24:10 >> STARTTLS<EOL>
14/12/03 18:24:12 << 220 2.0.0 Ready to start TLS<EOL>
14/12/03 18:24:14 >> QUIT<EOL>
lots of codes in unknown language.
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Disconnecting from smtp.gmail.com:25
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Connection Closed Gracefully.