The mail function in PHP doesn’t work in Windows/IIS environment unless you set up an SMTP server and configure it. SMTP server now doesn’t come built in with Windows 7 either.
So here is a quick way for you to be able to send mails from your applications and test the mails you send out from PHP or any other applications using SMTP on your localhost. There are two advantages here. You can verify that the mails you are sending out from your applications are correct in format and content. It also stops sending real emails from your development or local servers avoiding unwanted delivery of mails during development and testing.
Follow the below steps:
- Install smtp4dev 2.0.9. Download it from http://smtp4dev.codeplex.com/releases/view/71614
- Configure it to run on localhost or 127.0.0.1 or on all hosts and on a Port of your choice. Default port is 25, but change it to something else if mails are not sending.
- Run smtp4dev and make sure that it is listening on the port you configured.
- Add the following configurations in PHP.INI
; For Win32 only.
SMTP = 127.0.0.1 (or the host you configured in smtp4dev); http://php.net/smtp-port
smtp_port = 25 (or the port you configured in smtpdev) ;
For Win32 only.
sendmail_from = firstname.lastname@example.org
These settings will be existing in the PHP INI file, so you just have to just modify them.
Now try sending an email from PHP. The mail will be caught by this application and will allow you to open it in Outlook to read the content.
If you don’t want to modify the PHP.INI file, you can define these configuration values runtime as shown below:
Hope it helps.