Tips & How-To's

Getting php mail() function running on Windows 8.1 with WAMP Server and configuring it to use Gmail’s SMTP servers

With the next Barcamp Bangalore looming round the corner, I’d pitched in to help with some of the website tasks. I installed the traditional WAMP stack with WAMP Server for Windows and started working with WordPress. Needed to get the email notifications working, saw that it wasn’t. Bit of research & found that I’d need a SMTP server or an equivalent of sendmail.

All the cool kids seem to be using Fake sendmail – I tried it to use with Gmail’s SMTP servers which uses authentication & TLS. Fake sendmail either would crash repeatedly or give a Socket Error # 10060 Connection timed out error.

Finally, after much trawling the Intarwebz, going through many forums & Stack Overflow posts, finally found this blog post which recommends using stunnel.

So this is what my php.ini settings look like:

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from

sendmail_from = <the gmail id>

;C:\wamp\bin\sendmail
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path

sendmail_path = "C:\wamp\bin\sendmail\sendmail.exe -t"

Yes, all parameters, except for sendmail_form & sendmail_path are commented. They are set in sendmail.ini & stunnel.

sendmail.ini:

smtp_server=localhost
smtp_port=25

; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=none

auth_username=gmail username
auth_password=gmail password

stunnel.conf

; Certificate/key is needed in server mode and optional in client mode
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

18 Comments

  1. ] No limit detected for the number of clients
    [.] stunnel 5.01 on x86-pc-msvc-1500 platform
    [.] Compiled/running with OpenSSL 1.0.1g-fips 7 Apr 2014
    [.] Threading:WIN32 Sockets:SELECT,IPv6 SSL:ENGINE,OCSP,FIPS
    [ ] errno: (*_errno())
    [.] Reading configuration from file stunnel.conf
    [.] FIPS mode disabled
    [ ] Compression disabled
    [ ] Snagged 64 random bytes from C:/.rnd
    [ ] Wrote 0 new random bytes to C:/.rnd
    [ ] PRNG seeded successfully
    [ ] Initializing service [ssmtp]
    [ ] Loading cert from file: stunnel.pem
    [!] error queue: 140DC009: error:140DC009:SSL routines:SSL_CTX_use_certificate_chain_file:PEM lib
    [!] SSL_CTX_use_certificate_chain_file: 906D06C: error:0906D06C:PEM routines:PEM_read_bio:no start line
    [!] Service [ssmtp]: Failed to initialize SSL context

    please help

    1. The stunnel.pem file is created during the install process, however the result was wrong. I deleted and recreated it with the following command:
      openssl req -new -x509 -days 36500 -nodes -config stunnel.cnf -out stunnel.pem -keyout stunnel.pem

      After this, I run stunnel.exe again. The screen still shows the previous error message but never mind. Just use Configuration => Reload Configuration. After this, I get several new lines in the window. There is the following line as well:
      Configuration successful

      I hope it helped.

  2. Hey Sathya, I have been wandering around on the internet to find some way of sending email from Localhost. Finally came across your blog and now I am able to send emails through xampp directly to my inbox.
    Thanks Sathya.

  3. Did not work for me but maybe it’s the program i am trying send the email with. What program did you use to send the email with? I am a pc tech and create website, the sendmail program worked fine in windows 7.

  4. Can’t send the email. I have configured it as above,

    2015.04.08 13:09:40 LOG7[main]: Closing service [ssmtp]
    2015.04.08 13:09:40 LOG7[main]: Service [ssmtp] closed (FD=512)
    2015.04.08 13:09:40 LOG7[main]: Service [ssmtp] closed
    2015.04.08 13:09:40 LOG7[main]: Closing service [gmail-smtp]
    2015.04.08 13:09:40 LOG7[main]: Service [gmail-smtp] closed (FD=528)
    2015.04.08 13:09:40 LOG7[main]: Service [gmail-smtp] closed
    2015.04.08 13:13:53 LOG5[main]: Reading configuration from file stunnel.conf
    2015.04.08 13:13:53 LOG5[main]: UTF-8 byte order mark detected
    2015.04.08 13:13:53 LOG5[main]: FIPS mode disabled
    2015.04.08 13:13:53 LOG5[main]: Configuration successful

  5. Thanks for this man, however i get the following error in stunnel, please help
    [ ] Cron started
    [ ] No limit detected for the number of clients
    [.] stunnel 5.20 on x86-pc-msvc-1500 platform
    [.] Compiled/running with OpenSSL 1.0.2d-fips 9 Jul 2015
    [.] Threading:WIN32 Sockets:SELECT,IPv6 TLS:ENGINE,FIPS,OCSP,PSK,SNI
    [ ] errno: (*_errno())
    [ ] GUI message loop initialized
    [.] Reading configuration from file stunnel.conf
    [.] UTF-8 byte order mark detected
    [.] FIPS mode disabled
    [ ] Compression disabled
    [ ] Snagged 64 random bytes from C:/.rnd
    [ ] Wrote 0 new random bytes to C:/.rnd
    [ ] PRNG seeded successfully
    [!] stunnel.conf:91: “socket = l:TCP_NODELAY=1”: Specified option name is not valid here

    [!] Server is down
    [ ] Executing cron jobs
    [ ] Cron jobs completed in 0 seconds
    [ ] Waiting 86400 seconds

Leave a Reply

Your email address will not be published. Required fields are marked *