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 php.ini
:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = "C:\xampp\sendmail\sendmail.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_path
is 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 SMTP
, smtp_port
, and 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_path
commented 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
php.ini
'ssendmail_path
directive to it makes sending email much faster. Personally, I imaginesendmail.exe
chewing 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
sendmail.exe
intoC:\usr\bin
, this allows some programs that expect to be run on a Unix-based OS to run on WindowsHere is some info in the PHP manual that helped me work this out.
And...
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.