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.
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:
- smtp_server
- auth_username
- auth_password
Get them filled in, an example would be as follows:
auth_username=outgoing@justrealized.com
auth_password=dp2hsn12
Most SMTP servers require authentication. I just setup an email through my Media Temple account. (By the way, i.justrealized.com is hosted by Media Temple, if you’re interested in their service and would be kind enough, consider quoting ‘RYNSE.COM’ without quotes as your referrer. This would give me a bit of discount for my yearly subscriptions. Thanks.)
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.
And that’s all. Now for some testing.
3. Let’s test it out
$from_name = "Justrealized";
$from_email = "outgoing@justrealized.com";
$headers = "From: $from_name <$from_email>";
$body = "Hi, \nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail from Justrealized";
$to = "somewhere@justrealized.com";
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:

Hope it works for you. Please correct me if I missed out anything.
(Those aren’t my email, if you sent emails there your emails will get sucked into some blackhole.)
Possibly related:
great, works!
May 23
[...] How to use sendmail in XAMPP for Windows (tags: sendmail PHP XAMPP) [...]
Jun 05
I’ve all configured but always this error :
Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in D:\htdocs\test.php on line 9
… why ?
Jul 30
I have same problem Zaki but resolve it. Just search “smtp” in both php.ini for PHP and Apache, then uncomment them.
I have my own problem. I want to sent that email to my localhost mail setup in Thunderbird. the script said its successfully send put no email received in mu Thunderbird, Anybody can help me?
Aug 08
@mesol: You could try sending it to your web mail account like Hotmail or Gmail and see if it’s successful. Try those SMTP settings with your mail client to see if you can successful send out an email using those settings.
@mistervi: Do you have an smtp server set up on localhost?
Aug 08
@mistervi: also dont forget to restart the apache after making changes to the php.ini
Oct 16
its nice …
working for my mail page..
thank u…
Nov 13
I get this
Parse error: parse error in C:\xampp\htdocs\sendmailtest.php on line 3
Please help
mail me as well please
pcjonathan@gmail.com
Jan 02
Something is wrong in your line 3 of the PHP code. If you are using “:” with “endif” consider using braces and test it out again.
Jan 02
email send successfully but no receive email. where to debug.
Jan 14
If you confirm the mail to be sent out successfully, you probably can only check the server logs.
Perhaps it’s in your spam folder?
Jan 14
i tried the above setting for the mail sever but the mail doesn’t seem to send.
can any1 help
Mar 06
Thank you, thank you, thank you!!!
I’ve been searching for AGES for a solution to this, and this finally solved it. I wish all bloggers were as clear and as straight forward as you were in your post.
Mar 18
I have problems with sending email with sendmail
the sendmail crash with :
Message is missing sender’s address
I dont know what is missing
Apr 14
I tried the above setting for my XAMPP in XP localhost. But it did not worked.
It gave me error
Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\xampp\htdocs\dev\test.php on line 5
Apr 18
wow it doesn’t work. what a surprise. i have been searching for at least amonth and i still can’t figure out how to get the mail function to work. all the blogs say smtp=mail.yourisp.com and Verizon FiOS doesn’t have a f***ing mail server and even if it did it would require authentication. i hate life
May 15
tony: You can use AOL mail, I wrote a tutorial here.
May 15
[...] I wrote a guide on How to use sendmail in XAMPP for Windows but some people have difficulties successfully sending out an email with their web hosts. There is [...]
May 16
Tony: using an authenticating SMTP isn’t a problem with php either. You can set a password and username in your php.ini right underneath the smtp=mail.yourisp.com switch.
One other thing for eveyone to check is you ISP’s smtp settings as there seems to an increasing amount of them out there blocking port 25 as a forwarding smtp port from their clients unless they have opted for a static ip or made ajustments to use a different port. ( Seems most recomend 587)
Jul 18
Cheers boss – good show. Just what I was after. Just spent the last hour f*cking around with my php.ini file and XAMPP’s Mercury – no luck.
Thanks again!
L
PS. [This] form relies on JavaScript to send – baaaaaaaad bad :[
Jul 29
I literally tried everything but I couldn’t get this to work!! The mail seems to get sent but nothing appears in my google mail box.
Any advice guys?
Aug 01
@tkm: You can try with the guide with AOL mail
Aug 03
any idea how to set this up with an exchange server ? we have an exchange server on the same network the xampp and wordpress is runing, i tri to modify the vlues but no results.. any idea ? thanks in advance.
Nov 11
will it be possible to get setting for those of us that want to send from the mercury installed with xampp?
Nov 20
helpnet, I doubt that it is possible to set it up with an exchange server. I don’t know how Exchange server works though. Sorry.
kdele: I haven’t got any idea about Mercury.
Nov 20
Hi Im not getting it correct! Im using exchange, can you plzz help me!!!!
Jan 11
Ryan, this is for SMTP and not Exchange. I’m not sure how to make sendmail work with Exchange.
Jan 13
Thank you very much for this. It’s worked perfectly.
Jan 20
We use Xampp to host a WordPress site internally for use as an Intranet. I followed steps 1-3 and got it working using our Exchange 2003 server without a problem.
In the ‘sendmail.ini’ and ‘php.ini’ I changed the ‘smtp_server’ to the internal IP of the Exchange server, which is on the same subnet as the Xampp server.
We already have an Exchange mailbox for our Intranet, so I used those login credentials for the ‘sendmail.ini’ authentication settings.
I use the internal domain aliases as their email addresses, so for example, when creating a test email, I use ‘bobjones@domain.local’ as the users email address, and ‘intranet@domain.local’ as the ‘from’ address. (remember to change domain.local to match your own environment)
Remember, when you make changes to the ‘sendmail.ini’ and ‘php.ini’ files you need to restart Apache.
Thanks very much for posting your instructions, without them I would never have known where to start!
Mar 25
Hi…It is really helpfull code..I was trying this from many days…I finally can do this with this code..
Thanks A Lot..
Kinjal Solanki
Kinjal.mis@gmail.com
MIS Coordinator
District Watershed Development Unit,
Patan
Jun 15