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 brett on July 24th, 2009
Quote
@gordee
I’m glad it helped.
#2 by gordee on July 23rd, 2009
Quote
Hi. thanks for the post, it is the most helpful I’ve found anywhere and really has dissolved a huge amount of frustration. Thanks again.
#3 by Totte on April 29th, 2009
Quote
Hi, I tried the new version of xampp with sendmail and get the same errors. Im using mercury instead.. would be nice to get it working though. I will try it on another machine later on.
#4 by brett on April 28th, 2009
Quote
@byron
Thanks for following up.
Totte, here is the help link: http://glob.com.au/sendmail/help/
Post back when you figure it out!
#5 by byron on April 28th, 2009
Quote
make sure you’re running the latest version (i don’t know what version xampp distribute).
failing that i’ll really need the log files and stack traces; follow the instruction on the sendmail site if you require direct assistance from me
#6 by Totte on April 28th, 2009
Quote
Thanks,
well, the range check error comes after like 1 minute “processing”…
Anyway, here is my sendmail.ini
-totte
; configuration for fake sendmail
; if this file doesn’t exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS’s pickup directory cause sendmail to
; run quicker, but you won’t get error messages back to the calling
; application.
smtp_server=smtp.live.com
; smtp port (normally 25)
smtp_port=25
smtp_ssl=auto
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn’t provided
; if you want to override the value in the registry, uncomment and modify
default_domain=monkisoft.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=********
auth_password=*******
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the “MAIL FROM”
; command, it won’t modify the “From: ” header of the message content
force_sender=
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
hostname=localhost
#7 by brett on April 27th, 2009
Quote
@Totte
No, the DLL is fine. Maybe Byron, who posted above, can help determine what that error means. He is actually the developer of the program. On the fake sendmails site, here is a quote from the troubleshooting section:
“i’ve had a few reports of sendmail returning a “range check error”. i have tracked this to a bug in the indy sockets library and it has been fixed in version 18.”
Link: http://glob.com.au/sendmail/
In the meantime, would you mind posting your configuration ini? Be sure to take out any private info.
#8 by Totte on April 27th, 2009
Quote
Actually, it did not work. I mistakenly was visiting my “real” server
I get the error
09/04/27 15:54:33 : Range check error
And I found this about the dll that downloads from your page
http://www.greatis.com/appdata/d/s/ssleay32.dll.htm
does not look good.. ?
#9 by brett on April 27th, 2009
Quote
@Totte
Good to hear, glad you got it working.
#10 by Totte on April 27th, 2009
Quote
Hi again,
My xampp now works, with your settings and those dlls. It seemed I had to not only restart xampp, but also firefox to avoid that Range Check error.
Great, thanks!
#11 by brett on April 27th, 2009
Quote
@Totte
Would you mind posting your sendmail.ini file? — taking care to remove any personal information such as username / pass / email, etc.
#12 by Totte on April 27th, 2009
Quote
@Totte
I added the two dll’s and the error changed to
09/04/27 14:41:17 : Range check error
-totte
#13 by Totte on April 27th, 2009
Quote
Hi,
I get the error
09/04/27 14:36:56 : Must issue a STARTTLS command first
with this setup..
seems like my xampp is not using tls?
any hints?
-totte
#14 by byron on April 27th, 2009
Quote
some anti-virus product limit what applications are allowed to send mail via port 25 (SMTP). ensure that sendmail.exe is in your list of approved applications.
#15 by kelvin on April 25th, 2009
Quote
Initially, I did it my way and got this error from the log file:
Socket Error # 10061Connection refused
I latter did it your way and it was taking a lot of time. I checked the log file and found this error :
Connection Closed Gracefully.
#16 by brett on April 25th, 2009
Quote
Did you end up receiving the email? If not, which log file did you see that error in?