Now a days there are always tasks which require email notification, such examples are notify user on account creation, periodic notification for activities done by user, notify user on submission of form, etc. There are lots of other cases where you need to test the email and its content. In this post I'll be telling how can we send an email from our localhost.

FYI: Since Google Mail has changed its SSL security and removed support for v2 which is used by Sendmail.exe, those who will be configuring their GMail account will need to configured the Stunnel as well [Read More].

What you'll need:

Install the WAMP Server downloaded from WAMP Server site. By default it is installed in "C" Drive, at "C:\" location, keep it same so its easy to access.

Next download Fake Sendmail for Windows. Fake Sendmail, aka sendmail.exe, is a simple windows console application that emulates sendmail’s "-t" option to deliver emails. Extract the sendmail.zip file and move the folder here: "c:\wamp\sendmail". So your "sendmail.ini" file location will be like this "c:\wamp\sendmail\sendmail.ini"

To send an email we will need an email account with 1 step verification i.e. username and password (2 step verification will not work in this case). Now we'll need to configure some settings in sendmail.ini, which can be found in "c:\wamp\sendmail".

  • Line no. 14 | smtp_server=smtp.gmail.com # if gmail, if configured with stunnel use localhost
  • Link no. 18 | smtp_port=465 # if gmail, if configured with stunnel use 25
  • Link no. 27 | smtp_ssl=auto # if gmail, if configured with stunnel use none
  • Link no. 46 | auth_username=youremail@gmail.com
  • Link no. 47 | auth_password=yourpassword

There will be some lines which needs to be commented in sendmail.ini, please refer my sendmail.ini for reference.

Once we've configured sendmail.ini we'll need to configure php.ini. To open currently used PHP.ini file see [Screenshot1]:
[Screenshot1]

In php.ini file search for sendmail_path and set its value as:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Assuming you've not change any of the path from above.

Save and close php.ini file.

For these changes to take effect you must need to restart your WAMP Server.

By now you should be able to send emails, but if you're using Windows 8 or using GMail like me, then you'll need to do few more configurations, like I did:
These few more configurations includes installing and configuring Stunnel, and configuring Sendmail with Stunnel.

  • Download Stunnel form Stunnel site and install.
  • Locate your stunnel.conf file to configure, either using start menu or by going to "C:\Program file\stunnel" for 32Bits and "C:\Program file (x86)\stunnel" for 64Bits.
  • To edit this file you'll need administrative permissions, so just copy this file to Desktop and make necessary changes and then replace the original file in above location. Following are the changes you'll need to do:
    cert = stunnel.pem
    socket = l:TCP_NODELAY=1
    socket = r:TCP_NODELAY=1
    key = stunnel.pem
    [ssmtp]
    accept  = 465
    connect = 25
    [gmail-smtp]
    client = yes
    accept = 127.0.0.1:25
    connect = smtp.gmail.com:465
    ; To check logs you can enable logging using following lines
    debug = 7
    output = stunnel.log ; You will need to create this file if doesn't exists already and give proper permissions to current user.
  • Run Stunnel (Everytime you make any changes in stunnel.conf you'll need to reload it using "configuration => Reload Stunnel.conf")
  • Make sure you've made changes provided above with comment saying for stunnel

If you find any issue configuring stunnel.conf, please refer the stunnel.conf I've used.

Reference:

Tags: