How do I set up PHP to send email on Apache? (Windows) – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.
But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, php, email, sendmail, .
I am setting up an Apache server (2.2.14) on Windows, and borrowing ideas from an existing XAMPP configuration. I am now trying to set up email functionality for PHP (5.3.1). (It needs to be able to handle attachments, just like the XAMPP server can.)
I’ve noticed that XAMPP comes with fake sendmail for Windows, but several things about the configuration don’t make sense to me.
Here are a couple of lines from XAMPP’s
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ;sendmail_path = "C:xamppsendmailsendmail.exe -t"
This is weird because:
- It explicitly says “for Unix only,” yet
- I keep seeing tutorials that say to use this line for Windows, and
- the example file path wouldn’t even make sense in Unix
sendmail_pathis commented out by default
I wondered if
sendmail.exe is even necessary. So on my custom Apache server, which doesn’t have
sendmail.exe, I edited
php.ini to add the correct information for
sendmail_from. With that, it was able to send mail! But it’s very slow.
Then I went back to the XAMPP server and renamed the
sendmail directory, hoping to disable sendmail. That sort of worked – my PHP script claimed to have sent, but nothing happened.
So I’m very confused.
- My XAMPP server has
sendmail_pathcommented out, but apparently still uses the program it points to. How does it know?
- My Apache server has nothing in
sendmail_path, but can somehow send mail without it. How does it do that?
What do I actually need to do to configure the Apache server to send emails?
After further searching and testing, it appears that:
On Windows, PHP’s mail() function doesn’t necessarily need to hand email to another program on the same computer; it can connect to a mail server by itself
This, however, is inefficient and slow.
Setting up fake sendmail on the server machine and pointing
sendmail_pathdirective to it makes sending email much faster. Personally, I imagine
sendmail.exechewing up the data into nice, digestible bits, and spitting into the mail server’s mouth like a mother bird feeding her baby. Mmmm! But maybe I’m crazy.
If you put
C:usrbin, this allows some programs that expect to be run on a Unix-based OS to run on Windows
Here is some info in the PHP manual that helped me work this out.
Note: The Windows implementation of
mail() differs in many ways from the
Unix implementation. First, it doesn’t
use a local binary for composing
messages but only operates on direct
sockets which means a MTA is needed
listening on a network socket (which
can either on the localhost or a
Note: It is worth noting that the
mail() function is not suitable for
larger volumes of email in a loop.
This function opens and closes an SMTP
socket for each email, which is not
very efficient. For the sending of
large amounts of email, see the »
PEAR::Mail, and » PEAR::Mail_Queue
Apache is not really involved in any configuration for sending email. This is handled completely by PHP and the, in this case, local MTA. The MTA will be Sendmail or Postfix almost always. The configuration for this is in the php.ini file under [mail function] section called sendmail_path.