Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • Google+
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Windows ›
Using Sendmail on Windows

Using Sendmail on Windows

September 25, 2010 Windows Jesin A 80 Comments

windows category thumbnail

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
auth_username=username@gmail.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("youremail@domain.com","Subject","Email message","From: username@gmail.com");
?>

Save the file and access it via url (http://example.com/mail.php) you’ll see a blank page. Go and check youremail@domain.com’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 !!

Related posts:

How to Configure MSMTP for Cron linux category thumbnailHow to use MSMTP with Gmail, Yahoo and PHP Mail windows category thumbnailDig command on Windows OS windows category thumbnailHow to install Windows XP after Windows Vista/7 Default ThumbnailCreate your own email with Windows Live Custom Domains

Tags: php, sendmail

Comments

  1. Ghassen says

    September 13, 2013 at 9:09 am

    Thx Jesin ๐Ÿ™‚
    this tuto helped me a lot ๐Ÿ™‚

    Reply
  2. Jon says

    November 23, 2013 at 4:02 pm

    Does not work for me,
    I get this message in the sendmail error.log file
    13/11/23 02:29:42 : Socket Error # 10061Connection refused.

    Firewall is disabled.

    Reply
    • Jesin A says

      November 23, 2013 at 4:21 pm

      Hi Jon,

      What smtp_server are you using? It could be that your ISP is blocking outbound port 25 access.

      Open a command prompt and try this

      telnet <smtp_server> <smtp_port>

      If you should get a connection a 220 message like this

      220 mx.google.com ESMTP sg1sm59310787pbb.16 - gsmtp

      Instead if you get a “Could not open connection to the host” message it means either your ISP is blocking that port or a SMTP server is not setup in that address.

      Reply
  3. Jon says

    November 23, 2013 at 4:21 pm

    Sorry, my mistake,
    I somehow reverted the smtp_server value back to “localhost” from “smtp.gmail.com”.

    Reply
    • Jesin A says

      November 23, 2013 at 4:22 pm

      ๐Ÿ˜€

      Reply
      • mohamed nabih says

        December 19, 2015 at 2:03 am

        I make all steps but not work with me and it not display any error but not send

        Reply
  4. thiru says

    November 26, 2013 at 12:06 pm

    how to configure the sendmail in windows if anybody know the steps pls share with above mail id thanks for your helping

    Reply
  5. Chin says

    February 26, 2014 at 12:19 pm

    If I would like to CC to other people, could it be down, if yes, how? Thank you!

    Reply
    • Jesin A says

      February 28, 2014 at 5:01 pm

      Hi Chin,

      You would add them to the CC list and pass it as the 4th parameter of the PHP mail() function.

      Look at Example 3 on this page.

      Reply
  6. surya says

    May 29, 2014 at 11:26 am

    Thank you
    This helped me a lot ..Can you tell me how to add attachments to this mail

    Reply
  7. Engy says

    May 30, 2014 at 12:53 am

    Dear Sir;
    Where shall I put “sendmail” folder?

    Reply
  8. engy says

    May 30, 2014 at 1:22 pm

    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 …\wamp\www\mail.php on line 2
    can you help me please

    Reply
    • Alexander says

      June 29, 2014 at 7:30 am

      The same thing happened to me. I have tried using the telnet application to see if port 25 was working properly, but that’s not an application anymore.

      Reply
      • Jesin A says

        June 29, 2014 at 3:16 pm

        Hi Alexander,

        Do you have a mail server setup and running on Windows?

        Sendmail for Windows is not a complete mail server it only relays emails via other SMTP servers.

        So either you should have a mail server like Hmailserver installed locally or configure sendmail to relay via 3rd party SMTP servers.

        Telnet command-line tool is not installed by default. To install it go to Start, search for Turn windows features on or off and choose Telnet client.

        Reply
  9. sally says

    June 29, 2014 at 6:25 pm

    Warning: mail() [function.mail]: SMTP server response: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 wv8sm34425356wjb.1 - gsmtp in C:\wamp\www\mail.php on line 16

    this is the error that i got could you please help?

    Reply
    • Jesin A says

      June 29, 2014 at 6:31 pm

      Are you using a correct pair of credentials for the directives auth_username and auth_password?

      Reply
      • sally says

        June 29, 2014 at 6:33 pm

        yes i’m using my own email and password. should i chage it?

        Reply
        • Jesin A says

          June 29, 2014 at 6:37 pm

          Are you using your complete email address and not just the username portion? What are you using for smtp_server and smtp_port?

  10. sally says

    June 29, 2014 at 6:41 pm

    this is what ve wrote in the sendmail file

    smtp_server=ssl://smtp.gmail.com
    
    ; smtp port (normally 25)
    
    smtp_port=465
    Reply
    • Jesin A says

      June 29, 2014 at 6:48 pm

      Enable debug logging by removing the semicolon before the following line in sendmail.ini

      debug_logfile=debug.log

      Try running the mail.php script, open C:\sendmail\debug.log, put those lines in pastebin.com and share the link here.

      Reply
      • sally says

        June 29, 2014 at 6:57 pm

        I don’t find any file with this name debug.log

        Reply
        • Jesin A says

          June 29, 2014 at 7:03 pm

          I think PHP isn’t using sendmail at all. Open the php.ini file and look under [mail function] it should be like this

          [mail function]
          ; For Win32 only.
          ;SMTP = localhost
          ;smtp_port = 25
           sendmail_path = C:\sendmail\sendmail.exe
        • sally says

          June 29, 2014 at 7:22 pm

          yes i don’t have such an error anymore thank you so much, but it woks with me just one time . I received the email the first time ,I ve found it in spam ,but when i try it again i don’t receive any email. do you have an idea about it?

        • Jesin A says

          June 29, 2014 at 7:28 pm

          Try sending to different recipients. Enable debug logging and check debug.log for messages.

          Use Mail Tester to check why the emails are being classified as spam.

        • sally says

          June 29, 2014 at 7:54 pm

          could you please tell me how can i enable debug logging? because i tried many and adresses it doesn’t work

        • Jesin A says

          June 29, 2014 at 7:55 pm

          Look at my earlier comment.

      • sally says

        June 29, 2014 at 7:57 pm

        thank you so much you helped me

        Reply
  11. Tanmay Vij says

    July 19, 2014 at 10:58 pm

    It’s not working.. In wordpress I am getting an error: The e-mail could not be sent.
    Possible reason: you may have disabled the mail() function.
    When I checked the sendmail error log, I got this:
    14-07-19 22:53:41 : Socket Error # 11001Host not found.
    Please help me… How can I resolve this??

    Reply
  12. H C Teo says

    July 22, 2014 at 8:42 am

    It works generally well except that php crashed from time to time with this exception:

    madExecpt version: 3.01
    exception number: 1
    exception class: EIdSMTPReplyError
    exception message: Too many concurrent SMTP connections; please try again later.

    Do we need to close the connection after mail() function? How to do it?

    Reply
    • Jesin A says

      July 31, 2014 at 4:28 pm

      This error message is caused by the SMTP server you are using.

      What SMTP service are you using and how many emails do you send in a day?

      Reply
      • H C Teo says

        August 14, 2014 at 2:09 pm

        I recon its SMTP server too. It went back to normal after one or two days.

        Thanks!

        Reply
  13. nikunj says

    July 29, 2014 at 3:48 pm

    i use ssl 465 then why it connected to ssl 25 and mail not send in debug.log this line found..

    Connecting to ssl:25
    Socket Error # 11001Host not found.

    Reply
    • Jesin A says

      July 31, 2014 at 3:57 pm

      Post the configuration lines inside the sendmail.ini file.

      Reply
  14. Nitin says

    September 16, 2014 at 11:54 am

    Does it work on windows 8 ? I tried lot its not working for me

    Reply
  15. clodue says

    September 24, 2014 at 3:36 pm

    sendmail_path = C:\sendmail\sendmail.exe
    smtp_server=ssl://smtp.gmail.com
    smtp_port=465
    auth_username=user@gmail.com
    auth_password=pass

    then i get:
    Socket Error # 10060Connection timed out.

    i tried to change compatability mode for all users on sendmail.exe to
    run as admin
    run as XP SP3

    then i get:
    Error connecting with SSL.Error connecting with SSL.error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

    i tried to disable avast

    then i get:
    Connect timed out.

    Reply
    • clodue says

      September 24, 2014 at 3:57 pm

      i seem to have got it to work
      but im not sure why.

      i tried a few more changes in
      sendmail.ini
      changed:
      smtp_server=ssl://smtp.gmail.com
      smtp_server=smtp.gmail.com
      and
      hostname=
      to
      hostname=localhost

      then i got that gmail had blocked a login attempt
      i allowed that
      and now it seems to works

      Reply
      • eppersonjj says

        April 1, 2017 at 12:30 am

        Thank you to both Jesin A. for the awesome tutorial, and to Clodue for discovering these two changes! These two items were all it took to get mine to work as well.

        Reply
  16. Ankit Chauhan says

    September 30, 2014 at 2:57 pm

    Thanks Jesin,

    In my first attempt, I configured it on windows7 and it’s working.
    Keep posting such needful information.

    Reply
  17. John ezekiel says

    October 17, 2014 at 8:53 pm

    this are my errors

    4/10/17 23:21:20 ** --- MESSAGE BEGIN ---
    14/10/17 23:21:20 ** To: grandline18z@gmail.com
    14/10/17 23:21:20 ** Subject: Subject
    14/10/17 23:21:20 ** X-PHP-Originating-Script: 0:send_mail.php
    14/10/17 23:21:20 ** From: BoomPanes@gmail.com
    14/10/17 23:21:20 ** 
    14/10/17 23:21:20 ** Email message
    14/10/17 23:21:20 ** --- MESSAGE END ---
    14/10/17 23:21:20 ** Connecting to ssl:25
    
    14/10/17 23:21:23 ** Disconnected.
    14/10/17 23:21:23 ** Disconnected.
    14/10/17 23:21:23 ** Disconnected.
    14/10/17 23:21:23 ** Socket Error # 11001Host not found.
    Reply
    • Jesin A says

      October 17, 2014 at 8:59 pm

      I think there is an error in the smtp_server value. Check if ssl:// has a colon and NOT a semicolon.

      Reply
      • John ezekiel says

        October 17, 2014 at 9:17 pm

        smtp_server=ssl://smtp.gmail.com

        here is my setting on smtp_server

        Reply
        • Jesin A says

          October 21, 2014 at 12:05 am

          There might be multiple smtp_server values in the file. Paste the entire sendmail.ini file to pastbin.com and post its link here.

    • Vishal Roy says

      October 21, 2014 at 7:03 am

      Right click on sendmail.exe
      Properties
      Compatibility
      Change the configuration for all users
      Execute as Windows XP SP 3
      Execute as adminitrator
      create new password “Your application-specific passwords” – See https://support.google.com/mail/answer/1173270?hl=en

      In sendmail.ini
      smtp_server=smtp.gmail.com
      smtp_port=587
      auth_username=user@gmail.com
      auth_password=application password generated as above

      Enjoy!!

      Reply
  18. Patty says

    November 18, 2014 at 1:31 am

    Thank you. Very helpful procedure to get the mail() function working for me.

    Reply
  19. liya says

    December 22, 2014 at 6:19 pm

    i got error when i done this::

    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\mail send\mailsend.php on line 9

    plz help mee

    Reply
    • Jesin A says

      December 22, 2014 at 6:56 pm

      Did you put a semicolon before SMTP and smtp_port?

      Reply
      • liya says

        December 23, 2014 at 3:25 pm

        yah i put that…but the same answer is coming

        Reply
  20. Alvin says

    January 21, 2015 at 9:01 pm

    Hi i have a problem, so i set up my hmail server and also this sendmail for windows and had follow the steps accordingly, but i am still getting an error like this {[Warning: mail(): SMTP server response: 550 The address is not valid. in C:\wamp\www\controlpanel\mail.php on line 9]
    , please advise on what i should fo now.

    Reply
  21. steve says

    March 14, 2015 at 2:34 am

    Good Example, thanks

    What is the “license” for these sendmail binaries; I would like to use this at work

    Reply
    • Jesin A says

      March 17, 2015 at 1:09 am

      Hi Steve,

      The official page mentions “BSD license” – http://www.glob.com.au/sendmail/

      Reply
  22. Kimpe Andy says

    April 6, 2015 at 6:58 pm

    lol version no updated

    latest update 2011

    Reply
    • Jesin A says

      April 6, 2015 at 7:02 pm

      The software’s author has said that himself:

      unfortunately i no longer have the time or resources to provide any support or updates to sendmail.

      Reply
  23. obaid says

    April 13, 2015 at 1:21 pm

    i have got no errors but i didn’t receive any email..?

    Reply
    • Jesin A says

      April 13, 2015 at 1:28 pm

      Check the error.log file in the sendmail directory for any information.

      Reply
      • obaid says

        April 13, 2015 at 1:31 pm

        Socket Error # 10060Connection timed out.

        Reply
        • Jesin A says

          April 13, 2015 at 1:36 pm

          What do you have in the smtp_server directive? Try telneting to it to ensure your ISP isn’t blocking outgoing SMTP.

        • obaid says

          April 13, 2015 at 2:02 pm

          i just follow your steps where i get to know about stmp_server

        • obaid says

          April 13, 2015 at 3:31 pm

          dude i think my gmail 2 step verification making issues…

        • Jesin A says

          April 13, 2015 at 4:19 pm

          In the sendmail.ini file what value did you enter for smtp_server?

        • obaid says

          April 13, 2015 at 4:50 pm

          smtp.gmail.com

      • obaid says

        April 13, 2015 at 4:52 pm

        now error log is empty i have removed step two verification from gmail as well but still didn’t receive any mail…. i got message Email sent

        Reply
  24. gueye says

    April 19, 2015 at 1:56 am

    It doesn’t work for me I got this in error.log fil Connection Closed Gracefully.

    Reply
  25. arman says

    June 7, 2015 at 4:46 pm

    there is no error but it doesn’t work for me!!! would you please tell me what are the other programs I should install to solve this problem? I really need it!!

    Reply
  26. Art says

    September 17, 2015 at 2:58 am

    Thanks for the tutorial – helped us when porting a system from Linux to windows.

    thanks
    Art

    Reply
  27. Renukesh says

    December 20, 2016 at 3:26 pm

    i am getting this error

    sendmail: Error during delivery: Invalid address

    Reply
  28. Renukesh says

    December 20, 2016 at 3:26 pm

    I go ths error

    sendmail: Error during delivery: Invalid address

    Reply
  29. debendra says

    January 27, 2017 at 12:29 pm

    I have the following 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:\WinServer\wamp\www\mail.php on line 2

    Reply
  30. nauman says

    February 15, 2017 at 1:38 pm

    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 C:\wamp\www\sendEmail\index.php on line

    Reply
  31. Konstantin says

    March 10, 2017 at 4:24 pm

    Thenk you for article! It helped my very much!

    Reply
  32. Chiquado says

    September 23, 2017 at 2:16 pm

    After TroubleShoot Sendmail.exe i got message as: program not compatible. i am using window 7. help please.

    Reply
  33. Eugene says

    September 29, 2017 at 4:25 pm

    Dear Jesin,
    Your tutorial helps me a lots!

    My Case: Window 7
    sendmail.ini
    smtp_server=smtp.gmail.com will work.

    Bingo! Thank you!

    Regards,
    Eugene

    Reply
  34. Roch says

    October 4, 2017 at 9:54 pm

    Did not work. Here’s what I got:

    17/10/04 11:16:44 ** — MESSAGE END —
    17/10/04 11:16:45 ** Connecting to ssl:25
    17/10/04 11:16:47 ** Disconnected.
    17/10/04 11:16:47 ** Disconnected.
    17/10/04 11:16:47 ** Disconnected.

    I have this in my sendmail.ini:
    smtp_server=ssl://smtp.gmail.com
    smtp_port=465
    smtp_ssl=ssl

    Reply
  35. Jerome Greene says

    December 11, 2017 at 2:45 am

    Been working on this problem for a while now. Just found your website.
    My configuration is:
    Windows10
    Apache/2.4.25 (Win32)
    PHP Version 7.0.15
    I have set up my files exactly as your example.
    How do I test it?
    I do not own a domain. I just connect to the internet though my “isp”
    What I am tying to do is just send email using Xampp & Php from my computer to either my gmail account or some other account

    Thank You

    Reply
    • Jesin A says

      December 16, 2017 at 2:51 am

      Hi Jerome,

      Your best bet would be to use PHPMailer with you application. They have an example script for relaying emails via Gmail.

      Reply
  36. Raoilison Manitra Berthon says

    December 19, 2017 at 12:09 pm

    Hi! Thanks for your awesome tuto! I followed all indecated steps but it didn’t work
    here’s what is in my debug.log
    17/12/19 09:24:09 ** Connecting to ssl:25
    17/12/19 09:24:12 ** Disconnected.
    17/12/19 09:24:12 ** Disconnected.
    17/12/19 09:24:12 ** Disconnected.
    17/12/19 09:24:12 ** Socket Error # 11001Host not found.
    There is no error while sending the mail but i didn’t receive the mail.
    Any idea please?!

    Reply
    • Jesin A says

      December 19, 2017 at 6:21 pm

      Hi Raoilison,

      What is the value of your smtp_server setting?

      Reply
      • Raoilison Manitra Berthon says

        December 19, 2017 at 7:29 pm

        Thank you so much for your quick feedback!
        Here’s the value of the smtp_server:
        smtp_server=ssl://smtp.gmail.com
        and smtp_port=465

        I’m connected to the internet when sending the mail,

        Reply
  37. Edward says

    January 21, 2018 at 1:42 pm

    This is really helpful, love using windows for anything which has to be do with Linux coming across your tutorial has helped so much.

    Keep it up mate

    Reply
  38. dave says

    August 2, 2018 at 12:11 am

    Virustotal detected the sendmail for windows as ransomware.

    Reply
  39. hussain says

    July 7, 2019 at 11:01 am

    thank u very much
    it is so easy to do
    i did it for my windows 2016 server and it works perfectly

    Reply

Leave a Reply Cancel reply

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

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.