Saturday, June 8, 2013

Send email from localhost WAMP server using sendmail


Most of applications today are sending email to their subscribers or followers. During development stage, we need to test how this emails will look like. So, today we're going to configure our Wamp server to send an email. Here's the steps to achieve this:



  • Download the sendmail.zip through this link
  • Now, extract the folder and put it to C:/wamp/. Make sure that these four files are present: sendmail.exe, libeay32.dll, ssleay32.ddl and sendmail.ini.
  • Open sendmail.ini and set the configuration as follows:
    • smtp_server=smtp.gmail.com
    • smtp_port=465
    • smtp_ssl=ssl
    • default_domain=localhost
    • error_logfile=error.log
    • debug_logfile=debug.log
    • auth_username=[your_gmail_account_username]@gmail.com
    • auth_password=[your_gmail_account_password]
    • pop3_server=
    • pop3_username=
    • pop3_password=
    • force_sender=
    • force_recipient=
    • hostname=localhost
  • Access your email account. Click the Gear Tool > Settings > Forwarding and POP/IMAP > IMAP access. Click "Enable IMAP", then save your changes.
  • Run your WAMP Server. Enable ssl_module under Apache Module.


  • Next, enable php_openssl and php_sockets under PHP.

  • Open php.ini (C:\wamp\bin\apache\Apache2.x.xx\bin) and configure it as the codes below. Basically, you just have to set the sendmail_path.
  •        
    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    ;SMTP =
    ; http://php.net/smtp-port
    ;smtp_port = 25
    
    ; For Win32 only.
    ; http://php.net/sendmail-from
    ;sendmail_from = you@domain.com
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    ; http://php.net/sendmail-path
    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
    
  • Restart Wamp Server
  • The most exciting part, lets test it! Create a php file with the sample codes below and save it as mail_me.php:
  • 
    
  • Don't forget to change the $to and $headers to set the recipient/sender/reply back address.
  • Go to your browser and type localhost/mail_me.php; You should then receive an email

Notes:
  • This may only work on wampserver 2.0 and higher.
  • In setting sendmail.ini, the error_logfile and debug_logfile settings should be kept blank unless you encounter an error. This is so the file will not keep in increasing in size.

Reference:

6 comments:

  1. this still gives me an error ... Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

    ReplyDelete
  2. Kasun

    i tried days to configure sendmail,finaly it worked perfectly,thanks a lot

    ReplyDelete
    Replies
    1. what kind of changes u made in sendmail. I did all changes mentioned in here but it didn't work out. Please help me out from the loop.

      Delete
  3. As claimed by Stanford Medical, It is in fact the ONLY reason this country's women live 10 years longer and weigh 42 pounds lighter than us.

    (And actually, it has NOTHING to do with genetics or some secret diet and EVERYTHING around "how" they are eating.)

    P.S, What I said is "HOW", not "what"...

    Tap this link to discover if this quick test can help you decipher your true weight loss potential

    ReplyDelete