Default configuration of XAMPP do not allow to send emails through localhost. Here is the configuration for XAMPP to send email using a gmail account.

First you need to upgrade sendmail to the latest version.

  1. go to http://glob.com.au/sendmail/ and download sendmail.zip
  2. backup files in xampp/sendmail/ directory.
  3. delete all files in xampp/sendmail/ directory.
  4. copy the downloaded zip file to xampp/sendmail/ directory and extract the file

Then open the php.ini file (xampp/php/php.ini) and search for [mail function]

Modify the following parameters accordingly.

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header = Off

Note: Modify sendmail_path parameter to your sendmail directory if you have installed xampp on an another directory.

Open the sendmail.ini (xampp/sendmail/sendmail.ini) and set following parameters accordingly. Comment all other settings.

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=****@gmail.com
auth_password=****
force_sender=****@gmail.com

Replace auth_username, auth_password, force_sender parameters with your gmail account details.

Once you have done the modifications you can test the settings using a test php email such as following;

<?php
$subject=”Hi There!!”;
$to=”<receiver_mail_address>”;
$body=”This is a demo email sent using PHP on XAMPP″;
if (mail($to,$subject,$body)){
 echo “Mail sent successfully!”;
}
else{
 echo “Mail not sent!”;
}
?>
PHP

About the Author

Sadupa Wijeratne

Sadupa Wijeratne is the founder of My Cute Blog. Currently working as a software engineer. Interested about latest technologies and love to learn by experience.

View All Articles