Thursday, October 2, 2014

PHP mail function using Gmail account in Windows XAMPP



1) When we test php mail code in  Windows XAMPP, we do  not have smtp server in localhost. Windows XAMPP has sendmail.exe, but do not have PHPmailer. The following setting will make mail function working in PHP in XAMPP.
2) For example, you install XAMPP in C:\xampp
in C:\xampp\sendmail\sendmail.ini:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=****@gmail.com
auth_password=*******
force_sender=****@gmail.com
in C:\xampp\php\php.ini:
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
 
3) Replace  **** to your gmail account name and password.
Restart Apace in XAMPP.
 
4) testmail.php to test if mail function is working
 <?php

    $message = "The mail message was sent with the following mail";
    $headers = "From: youremail@gmail.com";
    mail("youremail@gmail.com", "Testing", $message, $headers);
    echo "Test message is sent to youremail@gmail.com....<BR/>";
   
?>
Change youremail@gmail.com to your email account. You will receive an email. 
Video: PHP mail function using Gmail account in Windows XAMPP

5) PHPmailer is another option to send email in PHP. 
reference:
http://jiansenlu.blogspot.ca/2011/08/php-send-email-using-phpmailer-and.html

For Linux, refer to:
https://www.digitalocean.com/community/tutorials/how-to-use-gmail-or-yahoo-with-php-mail-function

No comments:

Post a Comment