The PHP mail function is a wonderful feature of PHP but like all good things in life this function also has many drawbacks. On a Linux platform it requires sendmail to be installed, but coming to windows a SMTP server is needed to send email. So if you take a peak inside the php.ini file you’ll find the following line
[mail function] ; For Win32 only. SMTP = localhost smtp_port = 25
But the limitation here is you can only specify the SMTP server name and port, if the server requires authentication there is no provision for specifying the username and password. So unless you have a mail server configured to send local email without authentication there is no way to use the php mail() to send emails.
This is where sendmail for windows steps in. Created by Byron Jones it is also called fake sendmail. Using this tool you can configure PHP to use an external SMTP server with authentication to send emails using the php mail function. I’ll guide you step-by-step configuring sendmail for windows.
Step 1:- Download and Configure sendmail for windows
Download sendmail for windows extract sendmail.zip and place the contents in an easily accessible place. For this example I’ll place it inside the directory C:\sendmail. Next configure the sendmail.ini file. Open the sendmail.ini file using a text editor such as notepad. Edit the following values
[sendmail] smtp_server=localhost smtp_port=25 ;auth_username= ;auth_password=
For this tutorial I’ll be using gmail’s SMTP servers so the values will be
[sendmail] smtp_server=ssl://smtp.gmail.com smtp_port=465 email@example.com auth_password=gmailpassword
Save the file and move on to the next step.
Step 2:- Edit the php.ini file
In this step the the sendmail_path value has to be set in the php.ini file, before that comment out the unnecessary lines find the following line and put a semi colon (;) before them
[mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 ; For Win32 only. ;sendmail_from =
Now modify the following and set the sendmail path to where the sendmail.exe file resides in
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = C:\sendmail\sendmail.exe
save the php.ini file and restart apache web server or what ever we server you are using.
Step 3:- Test the settings using the mail() function
Create a new file named mail.php inside your document root (htdocs or public_html or www folder) and enter the following code into it
<?php mail("firstname.lastname@example.org","Subject","Email message","From: email@example.com"); ?>
Save the file and access it via url (http://example.com/mail.php) you’ll see a blank page. Go and check firstname.lastname@example.org’s inbox for any new mails.
Note: For emails to be sent through an external SMTP server your computer must be connected to the internet. Even though I may sound foolish, this might be the case if you’re testing on your home computer !!