The problem is that PHP mail()
function has a very limited functionality. There are several ways to send mail from PHP.
mail()
uses SMTP server on your system. There are at least two servers you can use on Windows: hMailServer and xmail. I spent several hours configuring and getting them up. First one is simpler in my opinion. Right now, hMailServer is working on Windows 7 x64.mail()
uses SMTP server on remote or virtual machine with Linux. Of course, real mail service like Gmail doesn't allow direct connection without any credentials or keys. You can set up virtual machine or use one located in your LAN. Most linux distros have mail server out of the box. Configure it and have fun. I use default exim4 on Debian 7 that listens its LAN interface.No matter what choice is your, I recommend you use some abstraction layer. You can use PHP library on your development machine running Windows and simply mail()
function on production machine with Linux. Abstraction layer allows you to interchange mail drivers depending on system which your application is running on. Create abstract MyMailer
class or interface with abstract send()
method. Inherit two classes MyPhpMailer
and MySwiftMailer
. Implement send()
method in appropriate ways.