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?

  • So what platform are you trying to use now? Is it Windows or UNIX currently? Jan 22 '10 at 16:23
  • Windows - sorry, I should have said. Editing question. Jan 22 '10 at 17:04

After further searching and testing, it appears that:

  1. 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

  2. This, however, is inefficient and slow.

  3. Setting up fake sendmail on the server machine and pointing php.ini's sendmail_path directive to it makes sending email much faster. Personally, I imagine sendmail.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.

  4. If you put sendmail.exe into C:\usr\bin, 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 remote machine).


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 packages.

  • Still the best (only ?) way to email with php mail(). Sad that the fake sendmail.exe isn't developed anymore but it support TLS so its fine. I just wanted to say to exclude the folder from the anti-virus else it will be REALLY long to send an attachment. Dec 7 '18 at 16:20

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.

  • MTA = 'mail transfer agent?' I know about sendmail_path; I wrote a whole paragraph about it and asked for some explanation. Jan 22 '10 at 17:36
  • Thought that you were looking at a different variable in a package rather than in php.ini Jan 22 '10 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.