Send email from localhost/WAMP Server using sendmail

Please try the previous solution [PHPMailer] first to send email from localhost. It is much more efficient.

The new WAMP Server’s PHP and stand-alone PHP v5.3+, are now NOT available with some of the extensions required to implement the previous solution [PHPMailer] (there is a workaround to install the missing extension(s), described in the linked article). So an alternate and much less efficient (slower, but negligible low-speed for development platform (WAMP/localhost)) solution can be implemented, as below:

Solution

This solution requires sendmail.exe (a Command Line Interface (CLI) executable which accepts email from PHP, connects to an SMTP server and sends email). You will not require to use it by command, don’t bother about it ๐Ÿ™‚ Download the sendmail.zip and follow these steps:

  • Create a folder named “sendmail” in “C:\wamp\”.
  • Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
  • Open the “sendmail.ini” file and configure it as following
    • 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

    You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. Enable these log file settings if you don’t get able to send email using sendmail.

  • Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:
  • Enable “php_openssl” and “php_sockets” extensions for PHP compiler:
  • Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):
    [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.
  • Create a PHP file and write the following code in it:
    <?php
    $to       = 'recipient@yahoo.com';
    $subject  = 'Testing sendmail.exe';
    $message  = 'Hi, you just received an email using sendmail!';
    $headers  = 'From: [your_gmail_account_username]@gmail.com' . "\r\n" .
                'MIME-Version: 1.0' . "\r\n" .
                'Content-type: text/html; charset=utf-8';
    if(mail($to, $subject, $message, $headers))
        echo "Email sent";
    else
        echo "Email sending failed";
    ?>
  • Make appropriate changes in $to and $headers variables to set recipient and sender (“From” header) addresses. Save it as “send-mail.php”. (You can save it anywhere or inside any sub-folder in “C:\wamp\www”.)
  • Open this file in browser, it MUST work now ๐Ÿ™‚
Update (2-Dec-2012)
Please ensure that 2-steps-verification is disabled in GMail if you are using GMail’s SMTP server to send email (sending email using GMail), otherwise you might get “Email sent” message but the email won’t get sent actually. (If you don’t know about 2-steps-verification, you don’t need to worry about it, it is disabled by default.) Thanks to Naveen.
Update (25-Mar-2013)
If the path to the sendmail.exe contains “space” (for example, “C:\Program Files\PHP\sendmail\”) then PHP would not be able to locate it. So, either store the sendmail.exe at a “non-spaced” location/path OR write the path in DOS style “C:\Progra~1\PHP\sendmail\” in the php.ini (sendmail_path = "C:\Progra~1\PHP\sendmail\sendmail.exe -t -i"). Thanks to Douglas.
Update (3-Apr-2013)
Windows 8 users, please check Mark’s comment if email sending is failing (may be because of …
Socket Error # 10060
Connection timed out
).
Update (3-Apr-2013)
I think all possible errors are now covered in the comments section, so I am closing the posting of comments for this article. If you are getting any error or a message like “Email sending failed.”, you can send email to me at nikunjbhatt84@gmail.com. Uncomment the “debug_logfile” and “error_logfile” settings and specify “debug.log” and “error.log” (without quotes) respectively for these 2 settings. Then run the send-mail.php script in browser; if there is any problem/error, the error.log will get created in the “sendmail” folder. Please attach those 2 files as well as, php.ini (C:\wamp\bin\apache\ApacheX.Y.Z\bin\), sendmail.ini, and send-mail.php, along with the email; I will check all these files and reply with suggestion if any. Thanks you all for the overwhelming responses.
Update (22-Jun-2013)
sendmail.exe may not work on slow internet connection like dial-up and 2G/GPRS. So you should try this solution with broadband or 3G or any other faster internet connection. I tested this solution with Tata Docomo 2G SIM into Motorola Milestone XT800 as well as into a 3G dongle, but email wasn’t sending. The error logged into the sendmail’s error.log file was: Socket Error # 10060<EOL>Connection timed out. All worked fine after I disconnected Tata Docomo 2G and tried with BSNL Broadband and Idea 3G (on the same dongle). So, I assume Tata Docomo 2G/GPRS, BSNL Dial-up, Airtel GPRS etc. slow connections would not work when using sendmail.exe, may be because of inability of synchronization of communication between sendmail.exe and the mail server on slow internet connection.
Update (06-Dec-2013)
For Windows 8 users:
From Shridharan Perumal:

Few months ago, using your tutorial, I configured mail server in WAMP succesfully. I reinstalled WAMP and tried the same and did as mentioned in the comments area but it didn’t worked (Socket Error # 10060). When Googled, I didn’t got any proper info to solve this. At last, I think I found a reason for this, this is due to Google’s modification. Configuring Stunnel is the solution for this. Here is the post that helped me — http://yogeshchaugule.com/blog/2013/configure-sendmail-wamp.
Update (31-Aug-2014)
From Imanuel Gittens:
After a bit of tinkering I finally got it to work. I had to enable less secure apps in my google account settings to get it to work. Just thought I should let you know in case you wanted to add it to your article. This is the link https://www.google.com/settings/security/lesssecureapps.
Thanks. You really helped me out.
4.49 avg. rating (89% score) - 139 votes

220 Comments.

  1. this error came what do i do???
    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() in C:\wamp\www\colleges\mail.php on line 10

    • You might have forget to COMMENT 2 settings in php.ini file.
      Ensure that semicolon is put against “SMTP =” and “smtp_port = 25” lines to make these lines as comment in php.ini file, as below:
      [mail function]
      ; For Win32 only.
      ; http://php.net/smtp
      ;SMTP =
      ; http://php.net/smtp-port
      ;smtp_port = 25

      • I got the same error which Nivas got. And the solution you gave, i tried that also but it is not working.

        • To send mail from localhost (WAMP, XAMP, or LAMP) you can use PHPMailer package(Download Link http://code.google.com/a/apache-extras.org/p/phpmailer/ ). After downloading this package ->Extract->Copy the full folder into your project folder->and use the doc folder for help. In example folder there is one file called testmailer.php. Change the parameter as your need.

          Examle:
          You have to change these parameters to your requirements.
          …….code…..
          $mail->Username = “abc@gmail.com”; // GMAIL username
          $mail->Password = “abcdefgh”;
          ……..code…..
          $mail->AddAddress(“desination@gmail.com”,”Nick name”);
          …….code…..
          For help you can mail us.. shashidharkulal@gmail.com

  2. You are awesome !!! works perfect for me!! Thanks!! ๐Ÿ˜†

  3. yipiii….works on me thanks ๐Ÿ˜€

  4. i got the email in my id but the From address is always the same….is it because of the authusername and authpassword……please help

    • Yes, this is obvious. By using the method mentioned in this article, you send email from your GMail account and so the From will contain your GMail address.
      This article demonstrates “Send email from localhost/WAMP Server…”, you should/can not use this method when putting the code on actual online server. Therefore it is Okay to get your GMail’s email address in From field when used on WAMP Server. On online server you will need to use PHPMailer or PHP’s core mail() function or PEAR’s Mail facility. When you send email from online server, you should be able to use your server’s email server and SMTP or sendmail facility to send email using mail() function or PHPMailer or PEAR Mail.

  5. 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() in C:\wamp\www\project\view-mail.php on line 292 Call Stack #TimeMemoryFunctionLocation 10.0007407584{main}( )..\view-mail.php:0 20.0059437416mail ( )..\view-mail.php:292 Email sending failed” >

    i followed all ur steps still getting same error

  6. hey there is no error but i still can’t get the mail

    • @suchitra, @Nidhi
      There must be some problem. Sometimes error will not be displayed but you can check for errors in the error log and debug log files. In the sendmail.ini file, specify files names for the “error_logfile” and “debug_logfile” properties. And after sending a trial email check the error and debug log files. Also, don’t forget to check the spam folder.

      • Anoop Kottappuram

        it may be due to the proxy setup.
        pleas check wether you put ON your proxy or NOT , if it is ON then remove your proxy and create a no proxy connection. ๐Ÿ™„ ๐Ÿ™„

        • ๐Ÿ˜›
          many problem here like a @suchitra etc…

          the problem same is everything is okey no error and succes when send email. BUT when check email not getting email. and teh solution is you must check sendmail_path = “C:\wamp\sendmail\sendmail.exe -t -i”

          the extrax file usualy in w:\wamp|bin|sendmail so same your path extrak file sendmile :

          sendmail_path = “C:\wamp\bin\sendmail\sendmail.exe -t -i”

          thanks a lot

    • i got msg as email sent but i didn’t receive any mail at all…

      i follow all the steps mentioned here..

      I see the error log it display as “Module ‘smtp’ already loaded in Unknown on line 0”

      and also i save the sendmail folder in bin…

      but it doesnt work…

      • I think there are more than one line with “extension=php_smtp.dll” in php.ini; there must be only 1 line for each extension. So, to solve the error, open php.ini, search for “extension=php_smtp” and if there are two lines with this same then remove any one of the lines.

        • yes sir i change that but still i got the message as “email sent” but no email in my account both in spam and inbox…

  7. there is no error but i m getting sending failed message

    • I may not be able to help you with only to “Sending failed” message. Now this will require to see your code myself. I will be happy to help you by Teamviewer.

    • Hi…suchitra
      I also got the same error….
      Make sure that the “sandmail” folder where the “sendmail.exe” store are in “C:\wamp\bin\”….Otherwise the massage can be failed.

      • The folder of sendmail can be anywhere on your harddisk. But wherever you put it, just be sure that you have also specified the same correct path for “sendmail_path” option in the php.ini file.

  8. Great job!

    After a long time of re-configuring and testing, i finally made it work!

    ๐Ÿ˜› ๐Ÿ˜›

  9. must say its WOOORKING. ๐Ÿ™‚

  10. Thank you very much! Perfect!!!!!!
    ๐Ÿ˜€

  11. Hi,
    I dont get any error and also dont see the message in my inbox or spam. I followed all ur steps.
    Where could the error be?

    • Please read the reply to the comments of “suchitra”.

      Also be sure about the port of your SMTP server. Sometimes webmasters changes SMTP port from default 25 to something else. You need to first verify this setting from server’s control panel or server’s customer help center.

  12. the post ws really helpful… thanku ๐Ÿ™‚ ๐Ÿ™‚

  13. hi thanks for the helpful post.
    I got no error but didnโ€™t get any email too. I tried to access the file error.log and debug.log . Please help. Thanks again for the post

    • Sorry for this late reply.

      Please read the reply to the comments of โ€œtanโ€.

      Also, if you are sending email from an online server, its must have an email account having the same email address which you are using for sending email from. You should ensure that your server supports SSL.

      You may also try changing port of GMail from 465 to 587 and/or removing “ssl” (delete “ssl”, keep blank) from “smtp_ssl” setting in the sendmail.ini file.

  14. thanks alot. worked well. ๐Ÿ™‚

  15. Hi, Thanks for the post.
    Really, it is helpful.
    ๐Ÿ™‚

  16. Oh my gosh!,
    it’s works!

    Wrote from Argentina!,

    Best Regards
    Juan.

  17. It Works in me but I can’t find the send-mail.php. What should I do?

    Please tell me I need this to work

    Thanks and God Bless, This post is very helpful ๐Ÿ˜€ Keep It up!!

    cheers

    John

    • Hmmm, now that’s strange! If it is working, then you know that where the send-mail.php is actually. If you have followed the same procedures as mentioned in this article, you are opening the send-mail.php in your browser!
      Take a look at the code below this line “Create a PHP file and write the following code in it” in the article. That code is saved in the send-mail.php file.

      • Hi, thanks for the answer. There’s something bothering in my mind but I dont know how to tell it. I just know how the logic goes.

        localhost -> Send Email -> Windows Mail

        It possible to do that using localhost? or its just only work when the site is live?

        • Sorry, I really can’t understand what you want to say by “localhost -> Send Email -> Windows Mail”. Please explain.

          • I’m sorry for not clearing about my question.

            Can I execute send email function from localhost then Im going to receive it on my Windows Mail?

          • Yes, it should work. Why don’t you just try it buddy. Good luck.

  18. Thanks for the post!

    But in my PHP->PHP extensions I have not found php_smtp.
    What does it mean?

    Best Regards,
    Dan

    • As I have wrote in the 2nd paragraph “The new WAMP Serverโ€™s PHP and stand-alone PHP v5.3+, are now not available with some of the extensions required to implement the previous solution.“, so, that required but missing extension is php_smtp in new WAMP Server versions.

  19. THANK YOU!!! for this simple and elegant solution.

  20. Anoop Kottappuram

    ๐Ÿ˜›
    Its a Useful and good Article. ๐Ÿ˜› ๐Ÿ˜›

  21. Mahmoud Ashraf

    It work ! , Thanks alot :mrgreen:

    Best Wishes,
    Mahmoud

  22. hi can we send multiple attachment from localhost

    can any one share me the code

    Thanks in advance

  23. thanks…

  24. ๐Ÿ˜ฏ
    This Kind Of ERROR occure

    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() in D:\wamp\www\Mail\send-mail.php on line 10
    Email sending failed

    I Follow all the step but somting problem..plz help me

    • You could have made mistake while configuring php.ini file. Check that all the lines (except first, [main function]), copy-pasted in this article, are commented (have semicolon as first characters in the lines). Most probably you have forgot to comment the line “smtp_port = 25” in php.ini.
      Also ensure which php.ini file your server is using, “wamp\bin\apache\apacheX.X.X\bin\php.ini” or “wamp\bin\php\phpX.X.X\php.ini”?

  25. I am getting this error log in debug log.txt file in send mail directory

    12/08/10 12:33:57 ** — MESSAGE BEGIN —
    12/08/10 12:33:57 ** To: d.sandip59@gmail.com
    12/08/10 12:33:57 ** Subject: Testing sendmail.exe
    12/08/10 12:33:57 ** X-PHP-Originating-Script: 0:test.php
    12/08/10 12:33:57 ** From: admin@gmail.com
    12/08/10 12:33:57 ** Reply-To: d.sandip59@gmail.com
    12/08/10 12:33:57 ** MIME-Version: 1.0
    12/08/10 12:33:57 ** Content-type: text/html; charset=iso-8859-1
    12/08/10 12:33:57 ** X-Mailer: PHP/5.3.8
    12/08/10 12:33:57 **
    12/08/10 12:33:57 ** Hi, you just received an email using sendmail!
    12/08/10 12:33:57 ** — MESSAGE END —
    12/08/10 12:33:57 ** Connecting to smtp.gmail.com:465
    12/08/10 12:33:58 ** Disconnected.
    12/08/10 12:33:58 ** Disconnected.
    12/08/10 12:33:58 ** Disconnected.
    12/08/10 12:33:58 ** Socket Error # 10061Connection refused.

    Please suggest me any solution for me. ๐Ÿ™

    • It seems you haven’t configured your GMail account properly. Please check the first image in this article for GMail account configuration under “Enable IMAP Access in your GMailโ€™s Settings” topic. If it is ok, try the things specified in my this comment to other user.

  26. Hi..
    I followed all the steps as you mention…But I can’t send mail. There is no error…But it returns that “Email sending failed” ….What should i do to fix this problem?

    • Hi…
      I just fixed the problem…Right now it work perfectly….The problem was…you mention that “sendmail” folder is in “C:\wamp\” directory…and when i keep that sendmail folder in “C:\wamp\bin\” folder then it run perfectly….any way Thanks a lot…

  27. Sayed Ahmad Naweed

    finally it worked properly

  28. Hi Nikunj,

    I have tried the above steps mentioned by you. But when I am opening the send-mail.php file in the browser the page goes blank. Even I am not getting error log file generated under the send mail directory. I have uncommented both error_logfile & debug_logfile in sendmail.ini but still the log files are not generated. I am using the wamp server version 2.2. Browser is mozilla 13.0.1
    Kindly help out and please let me know where I am doing mistake.

    • Please check my above comment reply to parimal’s comment otherwise I have doubt that I can solve your problem.

      • Hi Nikunj,

        I have studied your above comment for the Parimal. I have done the same configuration as you have mentioned in the article. I have already configured the php.ini file under wamp\bin\apache\apache2.2.22/bin/php.ini .Now I have done the same configuration for the wamp\bin\php\php5.3.13\php.ini also. But still I am not getting any mail and the error.

        The problem is that I am not able to get the failure logs so that I can forward it you. As the log files are not generated under the send mail directory.

        • If there is nothing in the sendmail’s log files or log files even doesn’t exist, it means the sendmail.exe is not executing when mail() function is called. So the reason could be that you could have set incorrect path to sendmail.exe, but as you have said you have confirmed this setting; another problem could be that the sendmail.exe is corrupt because of virus or anything else, try replacing it. If still there is no error in the log files, check for the files’ and its folder’s write permission.
          You should also check your spam folder of recipient and also check for filters.
          Also note that sending email from Yahoo and Hotmail’s SMTP server would not work, however this doesn’t seems to be a case in your problem. If still you are unable to send email, try older version of WAMP or try XAMPP, it is very much similar to WAMP Server.

  29. these is a very good thing……………i try it and it is a very good thing ๐Ÿ™„

  30. ๐Ÿ˜› Thanx . Very nice code n it works for me

  31. how to find the error log and debug log files pls guys help me

    • You would find the debug.log and error.log files in the sendmail’s folder if any error is occuring when sending email; check the configuring sendmail.ini file section in this article. If you aren’t receiving sent email and there is an error but the error.log and/or debug.log files are not generated automatically, then there could be a problem about write permission in the sendmail folder. In this case you can manually create blank error.log and debug.log files and give proper write permission to them.

  32. I am getting an error in error log file as under:
    Socket Error # 11001 host not found.

    What can be the possible reason?

  33. Nice article, worked for me ๐Ÿ˜€

  34. This works perfectly for me, except one tiny thing. I tried changing the info from my Gmail account to my Hotmail account. No matter what though, it still seems to continue sending emails from the Gmail account, even when the info in sendmail.ini is that of my Hotmail account. Any suggestions?

    • This must not be possible. After changing appropriate info in sendmail.ini save it, close it and reopen it before sending email and ensure that the info you had set is still there.
      You should also check your GMail and Hotmail accounts’ settings that they are not configured to send/receive emails from each other by their imports-email-from-another-account features.
      Also check that “from” and “reply-to” email addresses are properly set.

  35. I was try from long time…..

    Thank you very much…. from the bottom of my heart

    Thank you…. it is working

  36. I have got message Email Sent .But cant find mail in gmail.

    • Please ensure that you have correctly configured the sendmail.ini file and correct path to it is set in the php.ini file.
      Also check my replies to other commentators.

    • Nadeem,

      Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.

      Thanks in advance for you reply…

  37. I have tried it .It sent the message that email is sent but i did not find the mail in the reciever’s inbox

  38. The browser displays a message “Email not Sent” and the error.log file updates with a new mwssage 12/09/29 21:38:01 : Socket Error # 10060Connection timed out.

    • The error is occurring, I think, because you are trying to send through an SMTP server other than GMail, and that server is not responding on the port specified by you in the sendmail.ini file. Please check your server’s configuration for correct open port of its SMTP server. Another possibility could be that the server is configured to deny connection from outside of the server.

      • Gyana iam also getting this error in error.log, but getting email sent in browser… Can you please guide me how you fixed that issue

        Thanks

        • Everything works fine on Windows 7. Just tried installing on Windows 8 WAMP and getting Socket Error # 10060Connection timed out

          I’ve changed sendmail.ini from

          smtp_ssl=ssl

          to

          smtp_ssl=none

          and it’s all working on Win 8 too!

  39. hey i have done everything correctly but it is now show that Email Sending fail..
    what shud i do..

  40. how to fix this problem…??? the error meassage: 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() in C:\wamp\www\shopping\send-mail.php on line 18

    i already follow all the step provide..how to fix these error..?please help… ๐Ÿ™

  41. YOUR THE BOSSSSSSS…you save my life..!! thank you so much!!

  42. WEB | Pearltrees - pingback on October 24, 2012 at 9:16 pm
  43. Thanx a milion time ๐Ÿ˜€ omg I have read at least 20 blogs and tutorials about this. I have downloaded few aplplications and so on a you explain sending email from localhost so clearly and easily you have to get a Nobel Price at least from me ๐Ÿ˜€ I am so happy you won’t believe ๐Ÿ˜€ ๐Ÿ˜€ :D. I never leave a reply if I am looking for some problem but you make my day with this article so I have to leave a comment ๐Ÿ˜€ and sorry if it’s too long but I am really happy

    Big thank you !

  44. Hey thanks for this gr8 tut ๐Ÿ˜€
    I’m getting the following error
    http://prntscr.com/i68mw

    i don’t have any idea how to solve this.. ๐Ÿ’ก

    • It seems you don’t sufficient rights to run/execute the sendmail.exe. Please check sendmail.exe’s properties and give sufficient rights to your user account.

  45. rizwan siddiquee

    i have completed all process. but when i sent a message . i got successfully.
    but it did not reached there

  46. rizwan siddiquee

    i got apache_error is
    [Sun Oct 28 15:28:17 2012] [notice] Child 920: Starting thread to listen on port 80.
    The system cannot find the path specified.

    • Hmmm, that’s something new after many days on this article!

      Well, it seems a file is not available at a specified path and most probably, as Apache also logs some PHP errors, this error seems pointing towards sendmail.exe file. So, please check the php.ini file for correctness of the sendmail.exe’s path. (Remember there are 2 php.ini files, one for apache and another for php; please check above somewhere in comments for the actual paths to them and which you should edit.) And also check that you have sufficient rights to view/access/run/execute the sendmail.exe.

      Oh but if these are the problems, I should say, there is nothing new ๐Ÿ˜‰

  47. i is too good, as i think.

  48. Email sending failed ๐Ÿ˜ฅ

  49. i tried this selution but don’t work
    and “Email sending failed” showing in page

  50. thanks a tonnes yaa ๐Ÿ˜› ๐Ÿ˜› ๐Ÿ˜› r……… godd i searched so many articles… god bless you…. thanks and lots of thanks… ๐Ÿ˜€ ๐Ÿ˜€ ๐Ÿ˜€ ๐Ÿ˜€

  51. thanks it works!

  52. Anonymous - pingback on November 17, 2012 at 1:09 am
  53. ๐Ÿ˜› :mrgreen:

    Hi Nikunj,

    Thank You very much, your code made our work sucessfull !!!!!!

  54. 12/11/18 16:07:58 : Socket Error # 11001Host not found.

    ERROR

  55. It works great. Thank you โ— โ—

  56. ๐Ÿ˜› Working fine for me..!!

  57. Great work ! work perfectly !
    in my php extensions there is np php_smtp,
    but still work perfectly.
    Thanks

  58. I’m keep getting following error

    12/11/22 18:46:58 ** — MESSAGE BEGIN —
    12/11/22 18:46:58 ** To: ranuradis@gmail.com
    12/11/22 18:46:58 ** Subject: Testing sendmail
    12/11/22 18:46:58 ** X-PHP-Originating-Script: 0:send-mail.php
    12/11/22 18:46:58 ** From: sender@gmail.com
    12/11/22 18:46:58 ** Reply-To: sender@gmail.com
    12/11/22 18:46:58 ** MIME-Version: 1.0
    12/11/22 18:46:58 ** Content-type: text/html; charset=iso-8859-1
    12/11/22 18:46:58 ** X-Mailer: PHP/5.3.13
    12/11/22 18:46:58 **
    12/11/22 18:46:58 ** Hi, you just received an email using sendmail!
    12/11/22 18:46:58 ** — MESSAGE END —
    12/11/22 18:46:58 ** Connecting to smtp.gmail.com:465
    12/11/22 18:46:59 ** Connected.
    12/11/22 18:56:58 ** Disconnected.
    12/11/22 18:56:58 ** Disconnected.
    12/11/22 18:56:58 ** Disconnected.
    12/11/22 18:56:58 ** Connection Closed Gracefully.

    • Please ensure that Enable IMAP Access in your GMail’s Settings is enabled:
      Gmail Settings -> Forwarding and POP/IMAP -> IMAP Access

      Also, in the log you have pasted here, “sender@gmail.com” is set as From header’s value, is it your real email address or you have just changed it to hide identity here? “From” header must be same as your Gmail address.

  59. when i run the file in browser i got the msg Email sent but i didn’t get the mail.

  60. Please help me i didn’t get any idea from any of your comment….

  61. Hi Nikunj,

    Thanks for ur help my code was not running bcoz i activated 2 step verification in my gmail account now i deactivate my 2 step verification from my gmail account and my code is now working properly once again thanks alot….

  62. Setup Sendmail Wamp Server | Small Program Design - pingback on November 25, 2012 at 10:49 pm
  63. Great!!! thanks!!!!

  64. Hey there is an error…..
    “Email sending failed”

    Please help !

    • Please check others’ comments and my replies to them. If still you couldn’t solve it then I can’t help with only your provided information, please provide more information.

  65. Thanks its really working….. ๐Ÿ˜› ๐Ÿ˜€

  66. Hey,
    I did read your comments. Now the page is saying EMAIL SENT but I can’t find any mail though in my inbox. I rechecked my senmail.ini file but cant figure out what exactly is wrong. Would appreciate your help. Thanks.

    • Please ensure that 2-steps-verification is disabled in GMail. (If you don’t know about 2-steps-verification, you don’t need to worry about it, it is disabled by default.)

    • Sakshi,

      Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.

      Thanks in advance for you reply…

  67. yes it is disabled.

  68. Hi Nikunj I followed all the steps u provided below still i getting {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() in C:\wamp\www\TASKS\Email\mail.php on line 10} error..
    Please help me..

  69. Found the solution.. Restart the server. Thanx a lot. ๐Ÿ˜›

  70. hi ,

    somebody help me.. i think i already do the rigth thing but still i get sending email failed..

    appreciate for any help
    tnx,
    jr

  71. Hi ,

    Everything went fine but haven’t received any email in my inbox.

    Please help.

    Thanks
    Ani

  72. hi Nikunj! This is a really helpful post! Thank u so much for it! I followed everything according to how you explained! I am getting the ’email sent’ message but not the email on my Id! Read your replies to everybody else as well but not able to figure out what to do! Can u please suggest something that how it be detected where things might be going wrong?

    • MS,

      Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.

      Thanks in advance for you reply…

  73. Hi

    Great tut…the best ๐Ÿ˜Ž

    How can I get this to function with a localhost wordpress please..any idea?

    thx
    DJ

    • Thanks.
      Good question about integrating WordPress on localhost with this facility. I had thought about it too; but presently I don’t have much time to research on it. So please either try yourself or wait until I get time to do this. However, I think this must not be difficult. I don’t remember but I think there is some option to configure email related info when installing WordPress, please check it. I tried a little bit to find config related to emailing in WordPress files but found nothing yet. Good luck.

      • Nikunj,

        There are plenty of WordPress plugins capable of using smtp/ssl. I host my own WordPress server with all the apps (Apache2.2.19, PHP5.3.6, mySQL5.x.x). Therefore, I use 3rd party mail servers (gmail) to send outgoing mail via my WordPress website applications. Therefore, no need to use “sendmail” to obtain 3rd party mail server. WordPress use PHPMailer…

        • I didn’t get your point by ” I host my own WordPress server with all the apps…”. Have you installed WordPress on your own computer (WAMP or XAMPP (localhost))?

          Sure, WordPress is using PHPMailer, and PHPMailer is the best method for sending email, but it can’t be used if php_smtp extension is not available for PHP compiler. Therefore I have described an alternate method in this article which uses sendmail.exe for sending email from localhost. I think you haven’t read the first two paragraphs of this article.

          • Aloha Nikunj,
            I did read your “wonderful” article and the first two paragraphs. My hosting (localhost) environment is not a WAMP or XAMPP. Nevertheless, I am using a PHP application that’s outside the WordPress environment application. Therefore, the PHP application does not use the WordPress wp-mail function. Therefore I am interested in implementing “sendmail”. I have installed “sendmail”. I have tested sendmail using Glob’s batch example (cmd). The batch works great! However, testing with your above scripts, I get the “Email sent” message. Nevertheless, no gmail in my inbox. Yes, I will re-read your comments from above comments for “not receiving mail in their inbox”. Unfortunately, your commentor’s do not indicate what they did to fix the problem of “Email sent” but no mail in their “in-box”. Sorry for the Blah… Blah…

            I personally want to thank you for wonderful article. I investigated (search) many articles on “sendmail” and none could articulate the procedure for installing “sendmail”.

            Kind Regards,
            from Hawaii Island

          • Thank you Douglas. I post here only those content which I haven’t found elsewhere, no copy-paste. I think “About this Blog” page would interest you.

            Yes, it’s unfortunate that some commentators haven’t commented how they solved their problem of “Email sent” message but “not receiving email in their inbox”. What I believe is, most of them could have just forgot to configure one or two required things to implement this solution. And after knowing about it and solving the problem, they just don’t care about their comment; they might be feeling embarrassed about a silly mistake.

  74. Email sending failed

    may i know i get this error???
    please…urgent…

  75. You are cool man.This worked for me superb.
    For along time I was looking for this on various websites.You explanation is superb.
    Thanks.

  76. tnq..buddy… ๐Ÿ˜€

  77. Thanks for the useful post
    Iam using my gmail to send email.
    I have followed each step and read all comments/replies & getting message Email Sent in browser, but cant get email neither in yahoo inbox(recipient’s) nor in spam.
    Only got this line in error.log file Socket Error 10060 Connection Timed Out

    Thanks

  78. At last, a solution that works! THANK YOU ๐Ÿ˜›

    Took a while to realise that my email with Google isn’t @gmail but @mydomain so once I’d set auth_username= to that all works.

    No more uploading php files to a test rig on my remote server.

  79. worked right the first time. Super job!

  80. Followed the instructions and it worked perfectly. Thank you very much!

  81. Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\wamp\www\PHPMailer_5.2.2\class.phpmailer.php on line 2378

    Can you plz help out : how to solve this errors thanks

  82. Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\wamp\www\PHPMailer_5.2.2\class.phpmailer.php on line 2382
    Could not execute: /usr/sbin/sendmail

    • This is just a “Warning” which means it is not an “Error” and you can continue without worrying. Warnings mostly appears only on localhost and not on actual server, so you don’t need to worry about.

      I can provide 3 ways to hide this warning.

      1. Edit the php.ini file and set proper timezone. Search for “timezone” in the php.ini and set your region’s timezone identifier. By default, it is set to UTC. Example: date.timezone = UTC
      2. Use “date_default_timezone_set()” function to set proper timezone at top in your email sending file. For how to set timezone using “date_default_timezone_set()” function, check this page: http://in1.php.net/manual/en/function.date-default-timezone-get.php
      3. Hide the warning by disabling “Warning” messages in php.ini. Set “error_reporting” to “E_ALL & ~E_NOTICE & ~E_DEPRECATED” or “E_ALL & ~E_DEPRECATED“.

      To see the timezone for your region, check this page: http://in1.php.net/manual/en/timezones.php.

  83. ๐Ÿ˜Ž ๐Ÿ˜Ž ๐Ÿ˜Ž ๐Ÿ˜Ž Thanks

  84. hi i am developing a website and i need to send a mail in my website but i cant send a mail.
    error occur:SMTP ERROR:Could not connect to smtp host

    and im using wamp server there i cant find smtp module what can i do
    pls help me

    • The SMTP ERROR mentioned by you could occur if SMTP server’s address or username or password or port is incorrect. It could also occur if server doesn’t accept connection from outside of its own server space. Please enable logging in sendmail.ini file and check the logs for more info about the error.

      The solution provided in this article doesn’t require php_smtp extension.

  85. thanks for ur reply
    what we have to specify in default domain of the sendmail.ini file
    can you explain me clearly about the configuration and provide me a code for sending mail using wamp server….
    but in wamp server i wont have php_smtp in php extension

    • Everything you need to know is written clearly and in easy grammar in this article and in my reply-comment. If you can’t understand something, please ask to someone whoever is nearby you.

  86. thanks !!! ๐Ÿ˜€

  87. how do we do that for lamp server ?

  88. I Have apache 2.2 server installed . i am trying to send feedback to the gmail email id from php script. when submitted i am getting the error Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\wamp\www\kvksite\feedback_form.php on line 14
    I have not done any changes in php.ini. lphp.ini the server uses is in wamp/bin/apche2.2/bin directory.
    Kindly suggest me step by step how to solve this problem.

    • You said “I have not done any changes in php.ini.” actually you need to make changes in php.ini. Please read this article carefully and specially about changing the php.ini file.

    • Thanks Nikunj, its working. ๐Ÿ˜›
      Now I could send the text in the text area to my email id from the feedback form. Please guide me how to get the jpg attached in the feedback form to my email-id. Now I am saving the jpg to a folder on my local system and path in the db. Along with the feedback text i want the jpg also to be attached to my email.

  89. I’m having trouble… all things is setup and working but the message body turns to a .txt file and downloadable… it is not the usual message bod when it sends.

    • This shouldn’t happen with the PHP code supplied in this article. You could have merged other code with the code in this article. Please ensure that you have NOT this line in $headers:
      Content-Disposition: attachment
      If you have this code than remove it.

      • I don’t have that line of code. but this is i have now.

        $to = $uemail;
        $subject = “ScribeNet Email Confirmation”;
        $message = “HI! Ciao!”;

        $headers = “From: gee@yahoo.com” . “\r\n” .
        “Reply-to: geet@yahoo.com” . “\r\n” .
        “MIME-Version: 1.0 \r\n” .
        “Content-type: text/hmtl; charset=iso-8859-1\r\n”;

        if(mail($to, $subject, $message, $headers))
        {
        echo “Email Sent!”;

        }
        else
        {
        echo “Email Sending Failed”;

        }

        • Correct the lines as following:
          "Reply-To: sender@gmail.com" . "\r\n" .
          "MIME-Version: 1.0" . "\r\n" .
          "Content-type: text/html; charset=iso-8859-1" . "\r\n";

          The "\r\n" does matter to write it outside other header contents.

          Also, you have misspelled text/html, you have written text/hmtl. This is the reason why your email body text is shown as attachment instead of normal HTML body text.

          Also capitalize “To” in “Reply-To”, it is correct format.

  90. ok no errors now

    just sending message failed

  91. i follow all the process from ur site but im still not getting email in my gmail.

  92. rajesh talasila

    I got this error in debug.log file
    — MESSAGE BEGIN —
    13-01-30 17:14:50 ** To: rajesh07590@gmail.com
    13-01-30 17:14:50 ** Subject: Testing sendmail.exe
    13-01-30 17:14:50 ** X-PHP-Originating-Script: 0:send-mail.php
    13-01-30 17:14:50 ** From: rajesh07590@gmail.com
    13-01-30 17:14:50 ** Reply-To: rajesh07590@gmail.com
    13-01-30 17:14:50 ** MIME-Version: 1.0
    13-01-30 17:14:50 ** Content-type: text/html; charset=iso-8859-1
    13-01-30 17:14:50 ** X-Mailer: PHP/5.4.3
    13-01-30 17:14:50 **
    13-01-30 17:14:50 ** Hi, you just received an email using sendmail!
    13-01-30 17:14:50 ** — MESSAGE END —
    13-01-30 17:14:50 ** Connecting to smtp.gmail.com:465
    13-01-30 17:14:51 ** Connected.
    13-01-30 17:14:51 << 220 mx.google.com ESMTP ai8sm1395405pbd.14 – gsmtp
    13-01-30 17:14:51 >> EHLO localhost
    13-01-30 17:14:51 << 250-mx.google.com at your service, [1.22.205.225]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH XOAUTH2250 ENHANCEDSTATUSCODES
    13-01-30 17:14:51 ** Authenticating as rajesh07590@gmial.com
    13-01-30 17:14:51 >> AUTH LOGIN
    13-01-30 17:14:51 << 334 VXNlcm5hbWU6
    13-01-30 17:14:51 >> cmFqZXNoMDc1OTBAZ21pYWwuY29t
    13-01-30 17:14:52 << 334 UGFzc3dvcmQ6
    13-01-30 17:14:52 >> MDc4NTFhMDU5MA==
    13-01-30 17:14:52 << 535-5.7.1 Username and Password not accepted. Learn more at535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 ai8sm1395405pbd.14 – gsmtp
    13-01-30 17:14:52 ** Disconnecting from smtp.gmail.com:465
    13-01-30 17:14:52 ** Disconnected.
    13-01-30 17:14:52 ** Disconnected.
    13-01-30 17:14:52 ** Username and Password not accepted. Learn more athttp://support.google.com/mail/bin/answer.py?answer=14257 ai8sm1395405pbd.14 – gsmtp

    • Please check correctness of your password in sendmail.ini. Also ensure that 2-steps-verification is disabled in GMail.

      You may also try changing port of GMail from 465 to 587 and/or removing “ssl” (delete “ssl”, keep blank) for “smtp_ssl” setting in the sendmail.ini file.

  93. Thank you very much it is working fine

  94. I LOVE YOU!

  95. Thank you Mr nikunj , it worked for me …….. ๐Ÿ˜†

  96. itz showing an error …plz help me…SMTP server response: 550 Invalid recipient: abc@yahoo.in

    • Please try specifying an existing address. It is possible that the sendmail.exe would check for the existence of recipients’ email account(s) before sending the email.

    • I had sent an email to notify you about my reply to your comment but the email address (seeliyakvarghese AT gmail DOT com) provided by you is incorrect and therefore the email delivery failed; please provide your correct email address.

  97. hay i got it
    n thanks
    m try to solve my problem n i succeed and its now work ๐Ÿ™‚
    yuppieee
    once again thanks

  98. Just perfect.
    I have follow all step by step and it’s working at the first try. :mrgreen:
    Five minutes to implement it.

    Next step how to attach a document….

    Thanks to share your knowledge.

  99. mail() [function.mail]: Failed to connect to mailserver at “” port 465, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\sitemap\sendmail.php on line 10
    Email sending failed
    please help me solve my problem .i read alll comments but still i have this error

    • Please ensure that you have provided SMTP server address for smtp_server setting in sendmail.ini; and semicolon is prefixed against all lines except the last one in the [mail function] part in the php.ini file.

  100. hey…my email is send thanx a lot …this is such a nice article
    i only just remove square bracket from sendmail.ini in username and password and i got success my mail send to user
    now , my question is can diffrent user or multi ple user send mail using this sendmail or through localhost????

    • Yes, it is possible to use the same PHP script for sending email on behalf of multiple users. To achieve this, you need one common account of GMail. Write its email address and password in the sendmail.ini file. Then, in the send-mail.php file, substitute the From and Reply-To headers (sender@gmail.com) in $headers variable, to the appropriate users’ email address as following:

      $sender = $_POST['txtSender']; // get user's email address in form

      $headers = 'From: $sender' . "\r\n" .
          'Reply-To: $sender' . "\r\n" .
          'MIME-Version: 1.0' . "\r\n" .
          'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
          'X-Mailer: PHP/' . phpversion();

  101. thanx for rply

  102. i try it but error is undefine $sender and email sending failed

    • Have you stored sender’s email address in $sender variable as following? :
      $sender = $_POST['txtSender'];

      Here, txtSender is the name of an HTML Input element in which you should accept the sender’s email address before submitting the form.

      I can provide you more code but I think you should also use common sense to better understand this thing; it is good for you. It is like, I have provided an algorithm and you need to create a programming script from it. Good Luck. ๐Ÿ˜€

  103. yeah…k sure…thank you…

  104. now it comes email sending failed ๐Ÿ™

  105. Nikunj,
    Very Well Done!!!!

    Thank You!!!

  106. I dont find php_smtp in php extensions. Also, when i check error.log, I get the following error
    13/03/11 14:24:25 : Socket Error # 10060Connection timed out.
    I even moved the sendmail folder to C:\wamp\bin directory and changed sendmail_path accordingly but still got the same message. I once tried your solution and it worked perfectly fine but after some time i deleted it and now doing it again but I dont know why sending fail is coming .

    • This article describes sending email using sendmail.exe and it doesn’t require php_smtp PHP extension, otherwise (if php_smtp extension is available) PHPMailer is the best method for sending email.

      For the connection timed out error, check that sendmail.exe is not blocked by antivirus or firewall or by any other software. You should be able to manually add it to the allowed list of programs in your firewall application. Also try using 587 port of GMail and ensure that 2-step-verification is disabled in GMail and “smtp_ssl” is specified correctly in sendmail.ini and if you have proxy then check its configuration too.

  107. thank u guys ….. its really working ๐Ÿ˜† ๐Ÿ˜‰ ๐Ÿ™‚

  108. Nice. Its working…

  109. why don’t you post my comment ? i have asked so many times and you post only those comments that appreciates you which is unfair . if a person is asking you for help you should respond as soon as possible . i hope you reply and help me fix the bug .

    thanks

    • I have received and read total 3 comments from you, and posted 2 of them (including this). I haven’t posted your previous comment because there was nothing new in it. And I had personally sent an email to you to help you more, and asked you to send your send-mail.php, php.ini and sendmail.ini files to my email address so that I can view them for any problem in them; but I haven’t got reply from you, please check your inbox/spam folder. I have also sent a GMail chat invitation to help you personally, please sign into chat and check the invitation.

      I am not doing any unfair, I am not only posting comments of appreciation, instead I have told over the comment box to not to post comments to say just “Thank you” and told to give rating for this article instead. I am always ready to help everybody regarding the solutions posted on this blog. Still, I am sorry for any misunderstanding.

  110. very useful tutorial..man do have like this tutorial showing how to enable https using wamp?
    so glad, thanks

    • I also want to test https on localhost but I think it would not be possible because https requires SSL certificate for secure encrypted connection between client and server. SSL certi costs hundreds/thousands of dollars. Also, it may not be available for individual, may only be available for registered organizations; and may also need a dedicated/leased line internet connection with static IP address. Still, I hope to research more on it later sometime, can’t say when.

  111. When I keep the FORCE SENDER=
    and FORCE recipient=

    as it is …i.e if nothing is provided against the =

    The error log shows “sender’s address missing/recipient’s address missing”

    why?

    And irrespective of the “to” and “from” address in the actual code,the mail is forwarded and received in the forced sender/recipient’s address(if provided)…..
    Please help..

    • As I have said, force_sender and force_recipient settings in sendmail.ini aren’t mandatory. Be sure that you have correctly provided auth_username setting in sendmail.ini file; and sendmail_from setting is commented (has a semicolon at the beginning of this line) in php.ini; and you have correctly provided $to in the send-mail.php. The correct syntax for $to is : $to = "Recipient Name ". Also don’t provide same email address for sender and recipient.

  112. Hello,

    Trรจs bien รงa fonctionne ร  merveille.

    Merci beaucoup !

  113. I am receevg sent message ,but am gettg message in my inbox or spam.I checked out error_logfile,debug_logfile,it is sowing as
    error_logfile=error.log,
    debug_logfile=debug.log,

    I have installed postcast mail server and runned the above code.I also used send mail as u said.I folloed all the steps.My problem is i am able toreceive message in post cast but not gmail or yahho.

    • I am not able to understand your comment fully. Are you saying that you are getting following data in error_log and debug_log files?:
      error_logfile=error.log,
      debug_logfile=debug.log.,
      It doesn’t seem possible.

      And you may be able to receive email in postcast because you are sending through it, so what happens, I think, is you send email through postcast and it just copy it to your inbox because recipient is of user_id@localhost; the email is not going through GMail’s SMTP server.

  114. Thanks for ur reply n Nikunj,
    No nikunj i dint find error log file ,debug file inside send mail.I found it inside sendmail.ini it is displaying as
    error_logfile=error.log

    ; create debug log as debug.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable debugging

    ;debug_logfile=debug.log

    ; if your smtp server requires authentication, modify the following two lines

    I sent mail from post cast server(by clicking start)i am getting error:Thread 1:Access Denied.

    I have doubt is it required to use postcast smtp server?can’t i directly send mail?

    I tryed doing this and i got error,if i keep postcast open than it is showing message”Successfully sent”.

    If u dont mind can i make a call to u ?

  115. Nijunj
    is it required to use post cast server?
    I did without post cast and got error( NIVAS) i did what u mentioned in nivas comment but still i am getting same error.

    • I had tried installing and using many free SMTP servers before 1 year but had no success. I might had missed some configuration, but for a conclusion… I haven’t used SMTP server installed on localhost with WAMP.

      If PostCast mail server can work then any other SMTP mail server should work too.

      You may call me, you can find my contact number on TechWheels.net’s Contact page.

  116. You have uploaded a fantastic resource.

  117. Thanks it works for very nice articles…

  118. Hey Buddy this one is awesome
    Thanks man.

  119. Hi,

    I followed all the steps closely but I can email sending failed.

    This is my error message.

    13/04/01 16:01:31 : Socket Error # 10060Connection timed out.

    What should i do?

    • There are many such comments, please check my replies to those comments.

      • Hi,

        I have checked your replies but to no avail.

        But I am unsure on how to check my serverโ€™s configuration for correct open port of its SMTP server. ( I used smtp_port=465 for smtp.gmail.com)

        I also allowed access to sendmail.exe in my firewall.

        13/04/01 17:05:42 ** Socket Error # 10060Connection timed out.

        May you help me? Thanks!

Trackbacks and Pingbacks: