It can be difficult getting the PHP’s default mail functions to work when you run an apache server on windows instead of a unix environment. I ran into this problem with my server (running XAMPP), and thought others may benefit from a quick how-to. Another slight problem I had to get working was using an SMTP server that requires SSL connections (gmail for one). I didn’t realize that most recent XAMPP releases have sendmail built in already. This takes part of the hassel out, but we still have some configuring to do.
- First, ensure that you have an XAMPP release that does include the fake sendmail program. [More details here]
- Next, go to the XAMPP directory (often C:\xampp\), then open the ’sendmail’ subdirectory. You’ll most likely see the following files (default):
- sendmail.exe
- readme.html
- sendmail.ini
- sendmail_example.ini
- license.html
- Open the file sendmail.ini – this is where all of your SMTP server configurations will go, for example: SMTP Username, Password, Host, Port, etc
- My sendmail.ini file looks something like this:
; configuration for fake sendmail[sendmail]smtp_server=smtp.gmail.comsmtp_port=465; SMTPS (SSL) support; auto = use SSL for port 465, otherwise try to use TLS; ssl = alway use SSL; tls = always use TLS; none = never try to use SSLsmtp_ssl=autodefault_domain=brettshaffer.comerror_logfile=error.log; if your smtp server requires authentication, modify the following two linesauth_username=<USERNAME / EMAIL ADDRESS HERE>auth_password=<PASSWORD HERE>
-
- Note that this is a very simple setup. The variable names are fairly obvious, so simply fill in the SMTP server, port, ssl mode, username, password, and default domain / error log if you’d like.
- GMail requires an SSL connection, so my config was setup to use SSL port 465 and smtp_ssl=auto. If SSL is not necessary for your SMTP server, simply set smtp_ssl=none.
- Once the configuration is setup, make sure to save changes, then exit.
- If you are going to use SSL connections, you will need two additional files, available here (as of March 2009) – if this link no longer works, use the contact form and let me know.
- Extract the two compressed files (libeay32.dll and ssleay32.dll) to the same directory as sendmail.exe (for me, C:\xampp\sendmail\)
- Now, everything on the sendmail’s end is setup – now we just need to let the server know its there!
- Edit your PHP.ini file:
- XAMPP installations often have multiple files. If you are doubtful of the correct one, you can always go through and change them all. But before you do that, change the php.ini in \xampp\apache\bin\.
- Look for the following line:
sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”
-
- Uncomment the line (if already commented) by removing the semicolon at the start.
- Ensure that the path to sendmail.exe is correct (this is correct for me).
- Save and exit php.ini
- Restart the apache server and everything should work!

#1 by alexg on February 3, 2010 - 5:35 am
Quote
I am running XAMPP on vista and followed your instructions carefully. My example ini file under sendmail/xampp/xampp didn’t look like a proper ini file but more like what salang has posted here. I used a modified copy of your ini file and sendmail was complaining about the syntax of the ini file at line 1. After some time and a lot of frustration I replaced my sendmail.exe with a fresh download from their website at http://glob.com.au/sendmail/ and now it works like a charm. Seems some versions of XAMPP are bundled with a sendmail that expects the ini file in some other weird format. Hope someone finds this useful.
#2 by brett on February 3, 2010 - 7:19 am
Quote
Thanks! I’m sure visitors will find this information useful.
#3 by viduph on January 20, 2010 - 4:35 am
Quote
Could you please help me? Here are the steps I followed:
1. Modify php\php.ini (My XAMPP version is 1.7.1 and I cannot find apache\bin\php.ini)
2. Modify sendmail\sendmail.ini
3. Download sendmail_ssl.zip file (this step is done after I did not get success without it)
4. Restart Apache
5. Run send mail script
But all I get is no response, no error log file is created.
Here is the script to send email:
$from_name = “my name”;
$from_email = “myemail@gmail.com”;
$headers = “From: $from_name “;
$body = “Hi, \nThis is a test mail from $from_name .”;
$subject = “Test mail from $from_name”;
$to = “myotheremail@gmail.com”;
if (mail($to, $subject, $body, $headers)) {
echo “success!”;
} else {
echo “fail…”;
}
It prints “success!” on the screen but I don’t get any email in my gmail mail box.
I then use process monitor to see if sendmail.exe works (http://glob.com.au/sendmail/help/), it says success.
I don’t know what happens here.
#4 by brett on January 20, 2010 - 10:00 pm
Quote
I’m not sure what your problem is. Try printing your variables on the screen as debug at various points to ensure they are what you think they should be.
#5 by salang on January 16, 2010 - 4:53 am
Quote
The sendmail.ini in my xampp sendmail folder looks different from yours and the contents are as follows. Can you tell me why? My version xampp is 1.7.3
# Example for a user configuration file
# Set default values for all following accounts.
defaults
logfile “C:\xampp\sendmail\sendmail.log”
# Mercury
account Mercury
host localhost
from postmaster@localhost
auth off
# A freemail service example
account Hotmail
tls on
tls_certcheck off
host smtp.live.com
from [exampleuser]@hotmail.com
auth on
user [exampleuser]@hotmail.com
password [examplepassword]
# Set a default account
account default : Mercury
#6 by brett on January 16, 2010 - 11:06 am
Quote
Just copy and paste the configuration of my sendmail.ini file (above) into yours, follow the rest of the instructions, and see if that works. It is not supposed to be exactly how my setup is by default.
#7 by Robert M. on January 10, 2010 - 10:43 pm
Quote
You are a genius, Brett – thanks a million – finally all is working as it should on my Apache XAMPP using Gmail. Fantastic work worth financial rewards. I do like to donate tell me how
Robert M.
#8 by brett on January 11, 2010 - 6:25 am
Quote
Glad I could help, Robert. I put up a donate button on the right sidebar, but don’t feel obligated
#9 by brett on November 25, 2009 - 5:10 pm
Quote
Can’t see your script, sorry. Try the Contact form.
#10 by brett on November 25, 2009 - 5:09 pm
Quote
The sendmail directory is located in the XAMPP install directory — that is where the *ini files should be. Yahoo should also work, just change the smtp settings accordingly.
#11 by master on November 25, 2009 - 2:29 pm
Quote
EI buddy can you please help me, is this applicable if i want to send an email coming from my localhost XAMPP to yahoo mail?
This is my script I created, is this right, mate?
#12 by newdee on November 25, 2009 - 2:25 pm
Quote
ei buddy, im researching for my project to work, glad you can help me… I have this simple script
/////
////
And i want it to be send on a yahoo mail, just to test if my xampp is working.. i’m having trouble because your topic is about Gmail, yet mine wants to be on Yahoo.. also i’m having trouble locating those *.ini files… can you please guide me friend
#13 by Shariff on November 24, 2009 - 11:52 am
Quote
i followed the procedure u have written and ended up with this
……………………………………………………………………………..
Warning: mail() [function.mail]: Failed to connect to mailserver at “smtp.gmail.com” port 465, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\xampp\htdocs\sendmail.php on line 26
Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\sendmail.php on line 27
this error comes when i use ini_set() in mail file that is
ini_set(sendmail_from,”********@gmail.com”);
ini_set(SMTP,”smtp.gmail.com”);
ini_set(smtp_port,”465″);
…………………………………………………………………………
but when i remove this and change my php.ini
as
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = *******@gmail.com
sendmail_path = “\”C:\xampp\sendmail\sendmail.exe\”-t”
i get this error
Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 … Relaying denied. IP name lookup failed [117.192.137.222] in C:\xampp\htdocs\sendmail.php on line 23
………………………………………………………………………………
……………….
both errors accompany me after i changed the sendmail.ini file
and i have also added these two files libeay32.dll and ssleay32.dll
[sendmail]
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
default_domain=gmail.com
auth_username=********@gmail.com
auth_password=**********
…………………………………………………………………….
can u please tell me what is the actual problem i am facing ……….. help would be appreciated and grateful….
#14 by roxy on September 12, 2009 - 3:28 pm
Quote
Thank you! This worked like a charm.
#15 by brett on August 16, 2009 - 9:18 am
Quote
@Sri
It is a little hard to tell without knowing anything about the contact us script or your server configuration. With that info, I can’t tell whether it is a problem with sendmail or the script. Maybe you could contact the developer of the script.
#16 by Sri on August 10, 2009 - 1:16 pm
Quote
Hi
I am trying to send email to my gmail account using PHP contact us page and getting real hard time. I followed all the steps mentioned by you in this very simple blog. But unfortunately I am getting connect time out error. I am using wamp server 2.0 with fake sendmail program with ssl. Changed all the necessary configuration entries but none worked. Although my contact us page says, the email sent successfully. Not sure where is the issue?