Trusted answers to developer questions

How to configure XAMPP to send mail with the PHP mail function

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Today, communicating through mail in web apps is common, but there are some hurdles that might appear challenging if you are doing it for the first time. This shot shows you how to configure XAMPP to enable the use of the PHP mail function to send emails. This configuration will allow the built-in XAMPP sendmail.exe binary to deliver emails.

Step 1: Edit the php.ini file

  • Go to your xampp directory and locate the php folder. Inside this folder, locate the php.ini configuration file. Your path should look like this:
C:\xampp\php
  • Open the file in an editor and look for the [mail function] part, and replace the code there with the following:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

This command points to the sendmail folder, which we will now edit.

Step 2: Edit the sendmail.ini file

  • Go to your XAMPP directory once more and find the sendmail directory.

  • Open up the sendmail.ini file inside and find the [sendmail] portion.

  • Replace the code in this portion with the following code, exchanging the example values with your own information:

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
auth_username=your-gmail-account@gmail.com auth_password=your-gmail-account-password

If you are not using the Gmail SMTP server, please make sure to change it to your preferred server.

Now, with all these changes made and saved, restart your Apache server and you will be able to send emails from your application with the PHP mail() function.

A simple tip: locating the necessary section in these files can be tedious, so use the find word ability of your editor to get to those sections.

RELATED TAGS

php
xampp
gmail
apache
Did you find this helpful?