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 Judd Rogers Watts on March 2nd, 2010
Quote
Hi:
I have XAMPP running on my IBM Netvista (P4); it works well and I am very pleased with it. I have a PERL program that uses SENDMAIL which works on my Network Solutions hosting service. I’m importing it to XAMPP.
The program opens SENDMAIL with the following code:
my $sendmail = “/usr/sbin/sendmail -t”;
open(SENDMAIL, “|$sendmail”) or die “Cannot open $sendmail: $!”;
and prints the email document with lines like:
print SENDMAIL $from;
print SENDMAIL $send_to; #etc.
I believe I need to modify the PERL open statement. I have tried:
$sendmail = “C:\xampp\sendmail\sendmail”;
open(SENDMAIL, “|$sendmail”) or die “Cannot open $sendmail: $!”;
but had no luck. Also, I think I need an .ini file. I tried the following file:
C:\xampp\sendmail\sendmail.ini
with this as the file contents:
c:\xampp\sendmail\sendmail
smtp_server=smtp.bankmanasseh.com
smtp_port=30
default_domain=bankmanasseh.com
error_logfile=error.log
auth_username=manasseh@bankmanasseh.com
auth_password=qA10aPg25r
(bankmanasseh.com is my Network Solutions hosetd URL.) It still doesn’t work. I got no errors, no error log, and no email was sent. Can you help me?
Signed: Judd Rogers Watts
Owner of Manasseh
#2 by J on February 25th, 2010
Quote
I’m getting the following error when I try to launch a php file that performs an email:
Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\contact_parse.php on line 35
return_msg=Thanks , your message has been sent.
No email has been received btw.