How to use sendmail in XAMPP for Windows

The easiest way to start developing in PHP is to get XAMPP, the whole package can even be placed in a flash drive.

cdl_capture_2011-09-20-38_ 000

0. Objective

To get your PHP scripts to send an email out. This guide assumes you have XAMPP or XAMPP Lite. My environment is Windows Vista. (I use XAMPP Lite by the way)

My XAMPP is placed in C:\xampp\, so your configuration may be a little different. The files to be modified are sendmail.ini and php.ini.

1. Modify your sendmail.ini

Your sendmail.ini should be located in C:\xampp\sendmail\sendmail.ini. You only need to be concern with 3 variables here:

  1. smtp_server
  2. auth_username
  3. auth_password

Get them filled in, an example would be as follows:

2. Modify your php.ini

XAMPP places the php.ini inside C:\xampp\apache\bin\php.ini. You can open the file and do a search for ‘sendmail_path’. It’s at line 704 for me. You can simply uncomment that line.

sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”

And that’s all. Now for some testing.

3. Let’s test it out

$from_name = "YourName";
$from_email = "";
$headers = "From: $from_name <$from_email>";
$body = "Hi, \nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail ";
$to = ‘’;

if (mail($to, $subject, $body, $headers)) {
echo "success!";
} else {
echo "fail…";

Execute those codes and you should receive something in your inbox. Here’s what I see in Gmail:


Join the Conversation

1 Comment

Leave a comment