Results 1 to 24 of 24

Thread: Configuring PHP under Windows to use Gmail or External SMTP Server [SSL]

  1. #1
    Ultimate Lifeform Nimrod's Avatar
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    1,991
    Blog Entries
    24

    Default Configuring PHP under Windows to use Gmail or External SMTP Server [SSL]

    Configuring PHP under Windows to use Gmail or External SMTP Server [SSL]

    Keywords: SSL, SMTP Authentication, External SMTP, Google Apps, Fake Sendmail


    When installing and setting up Apache, PHP and MySQL on my Windows Server box I have a unique problem, I didn't run my own mail server. I got sick of having to deal with spam issues as well as ensuring maximum uptime or end up losing mail. I then decided to take advantage of Google Apps, which allows you to use Google Services for your domains including the Gmail Service, which allows you to have your email handled by Google. What's best? You still keep the domain name, so you get all the features of Gmail, but with your own domain name and you still retain full control of users. To see an example of the log on, check out http://mail.digiex.net.

    One big problem with this though, how do you configure PHP so it can send mail now that you don't run the mail service yourself? In the PHP.ini you can configure to use SMTP to drop off mail but it doesnt offer you many options, whats missing is SSL support which Gmail uses as well as SMTP authentication which yet again, Gmail uses.

    This is the best part, I found a "Unix fake sendmail" application for Windows, what this does is accepts mail in the same way Unix does, but then passes it onto another mail server and supports SSL and authentication.

    Configuration

    Note: If you are intending to use Gmail or Google Apps with Custom Domain, please read this for an update regarding the SSL problems.

    This configuration will talk you through setting up the service with Gmail using a Custom Domain. If you have not yet done this, you will need to set up Google Apps for your Domain by clicking here. Once you have enabled Gmail for your domain you will need to set up an account for webmaster or whatever email address you intend to use for your PHP Mails. Once the account is created you must log into it once and enable POP3 or IMAP under Settings, this usually then enables SMTP on your Gmail so that you can use it with this.

    If you are not using Gmail you will need to do some additional steps like setting up the SMTP server and port. You will need to find these out from your email provider. This does NOT work with Windows Live Domains due to the lack of SMTP.

    Step 1 - Download and Configure Sendmail


    The first step is to download Fake Sendmail created by Byron Jones. I have provided a copy which already has SSL supported added in and configured to work with Gmail which can be downloaded by clicking here.

    You will need to extract it somewhere on your Server. Its recommended you choose somewhere sensible because once set up you will need to reconfigure PHP if you change the path, so don't bother with your Desktop. If you have locked down Apache and PHP with a seperate locked down user account, that user account with need access to read and run applications in the folder where you store Sendmail. For the purpose of this guide, I have stored it in C:\inetpub\sendmail\

    Once extracted, open Sendmail.ini in your favourite text editor, Notepad will do. You will need to customize this configuration to your own. The lines highlighted in red must be changed and configured to your domain settings. Words highlighted in blue should ONLY be changed if you are not using Gmail for your email.

    Code:
    ; configuration for fake sendmail
    
    ; if this file doesn't exist, sendmail.exe will look for the settings in
    ; the registry, under HKLM\Software\Sendmail
    
    [sendmail]
    
    ; you must change mail.mydomain.com to your smtp server,
    ; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
    ; emails delivered via IIS's pickup directory cause sendmail to
    ; run quicker, but you won't get error messages back to the calling
    ; application.
    
    smtp_server=smtp.gmail.com
    
    ; smtp port (normally 25)
    
    smtp_port=587
    
    ; the default domain for this server will be read from the registry
    ; this will be appended to email addresses when one isn't provided
    ; if you want to override the value in the registry, uncomment and modify
    
    default_domain=domain.com
    
    ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable logging
    
    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
    
    auth_username=webmaster@domain.com
    auth_password=password
    
    ; if your smtp server uses pop3 before smtp authentication, modify the 
    ; following three lines
    
    pop3_server=
    pop3_username=
    pop3_password=
    
    ; to force the sender to always be the following email address, uncomment and
    ; populate with a valid email address.  this will only affect the "MAIL FROM"
    ; command, it won't modify the "From: " header of the message content
    
    force_sender=webmaster@domain.com
    
    ; sendmail will use your hostname and your default_domain in the ehlo/helo
    ; smtp greeting.  you can manually set the ehlo/helo name if required
    
    ;hostname=


    Once you have configured this you can save your sendmail.ini and Sendmail is configured. Its now time to move onto Step 2.

    Step 2 - Configuring PHP to use Sendmail

    You will need to open your PHP configuration (PHP.ini), you will then need to look for the [mail function] section. Once there, look for the line which asks for Sendmail path, you may notice it says for Unix only, but ignore this.

    Code:
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t"
    In this case, I am storing "sendmail.exe" in C:\inetpub\sendmail. If you are storing it elsewhere, be sure to declare it here. You also need to add the argument -t for it to work.

    Also ensure all other options under [mail function] is commented out using ; so that the sendmail path is the only option uncommented.

    Your [mail function] should now look something like this:

    Code:
    [mail function]
    ; For Win32 only.
    ;SMTP = localhost
    ;smtp_port = 25
    
    ; For Win32 only.
    ;sendmail_from = me@example.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t"
    
    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =


    You have now configured PHP to use your sendmail which should in turn send the mail via your Gmail account (or whatever account you configured). Now its time to test it...

    Step 3 - Test

    You will need to now run a php script under your PHP environment which sends mail via the PHP sendmail command. In my case it was easy to test with vBulletin.



    Once you have sent the email, check the Inbox for whichever account you sent it in a couple of minutes and the email should be there!

    If you received an email, congratulations you have configured your web server perfectly

    If not, there could be a problem. To help with troubleshooting heres a few things to check:

    Check the error log of the PHP script and make sure it didnt have any problems running the Sendmail command in PHP.
    Check the error.log in the Sendmail.exe directory and see if it had problems logging into your SMTP server to send the mail
    Make sure the receipt is not having email problems, try it with a few people with different mail providers incase theres a problem there.



    Attached Files Attached Files

    -Nimrod

    Have a question or need help? Post on the forum, thats why it's here. I will only reply to Digiex related issues via PM, not general help requests.
    If I helped you can say thanks by signing up for Dropbox with my referral link, we will both get an extra 500mb of space for free.


  2. #2

    Default thanks

    Hello, thank you, this is an excellent guide. Really helped me out.


  3. #3

    Default

    great post m8!

    i just followed your tutorial to the dot and got it to work..

    there was a slight hitch in between.. even though i changed the php.ini file, the phpinfo() on server still showed no value for sendmail parameters...

    i just restarted the server and voila.. mails came!!!

    i'm learning php and it feels nice to get things working.... thanks for your effort!


  4. #4

    Default Promblem when sending mail using fake send mail

    Hi all!

    I'm having a problem sending mail using fake sendmail, I have a windows 2003 machine with IIS and PHP,

    If i try to send mail via command line and a script I created in php, it all works fine.

    If i try to send mail via IIS I get this error:
    "Could not execute mail delivery program C:\Inetpub\sendmail\sendmail.exe -t"

    Thanks in advance for all your help,
    Jorge

  5. #5
    The Feature Man
    Join Date
    Aug 2008
    Location
    In Space
    Posts
    1,899
    Blog Entries
    19

    Default

    Quote Originally Posted by neozaga View Post
    Hi all!

    I'm having a problem sending mail using fake sendmail, I have a windows 2003 machine with IIS and PHP,

    If i try to send mail via command line and a script I created in php, it all works fine.

    If i try to send mail via IIS I get this error:
    "Could not execute mail delivery program C:\Inetpub\sendmail\sendmail.exe -t"

    Thanks in advance for all your help,
    Jorge
    Are you sure you configured your php.ini correctly? Make sure you set your sendmail directory correctly. should say, sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t" if thats the directory which you saved the sendmail program to.

    Also
    Quote Originally Posted by Nimrod
    Check the error.log in the Sendmail.exe directory and see if it had problems logging into your SMTP server to send the mail

    Make sure the receipt is not having email problems, try it with a few people with different mail providers incase theres a problem there.
    Found this post useful? Say thanks by signing up at Bitcasa.

  6. #6

    Default

    Quote Originally Posted by xzKinGzxBuRnzx View Post
    Are you sure you configured your php.ini correctly? Make sure you set your sendmail directory correctly. should say, sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t" if thats the directory which you saved the sendmail program to.

    Also
    Yes, the php.ini is configured correctly, I can send e-mails if I do php.exe C:\inetpub\snigdev\testemails.php in the command line, but via IIS doesn't work.

    It seems to be a premissions issue, but I can't find what more premissions do I have to give in the directory sendmail.exe resides.

    Thanks in advanced,
    Jorge


  7. #7

    Default

    neozaga,
    Check permissions for cmd.exe in system32 folder. I had the same problem. Having set Read and Execute to IUSR_MACHINENAME I've solved the issue.
    If doesn't help download ProcMon and see what inetinfo.exe fails to do.

  8. #8

    Talking Stunning!

    Thank you! What a great article. I've just written a post about this on my blog with a link to it.

    That was one of the most easy to follow - well explained and useful technical postings I've seen in a long time.

    I now have my Drupal site with mailhandler working like a dream - you superstar!

    Muah! - lol

  9. #9

    Default Doh!

    Looks as though I spoke a little too soon. The first test I ran no errors came back but subsequently I'm getting the same errors as everyone else:

    warning: mail() [function.mail]: Could not execute mail delivery program 'C:\inetpub\sendmail\sendmail.exe in W:\WWWRoot\mydomainname\includes\mail.inc on line 193.

    I have put sendmail.exe in the same directory as you just for simplicity sake. Also my php.ini file is correct with my sendmail_path pointing to the correct place and is the only line in the [mail function] uncommented.

    I have added IUSER_(MACHINENAME) with read and execute properties to cmd.exe in windows\system32 and rebooted my server.

    (Mail is being retrieved from the above address fine)

    Any ideas?
    Last edited by scifisi; 30-09-09 at 19:33.


  10. #10

    Unhappy Socket Error # 10054<EOL>Connection reset by peer.

    Hi
    I have a stand-alone PC connected only to the Internet. I work on Windows XP. I am trying to send mail in PHP using the mail() function. My working directory is c:\wamp\www.
    With the default settings in php.ini , i.e. SMTP=localhost and smtp_port=25, the mail() finction in PHP did not work.
    Since I do not have an SMTP server running in my standalone PC connected only to internet, I tried to use smtp of google.
    To send mail using wampserver, I followed your steps. I downloaded and installed sendmail in C:\inetpub\sendmail\
    Then, I set default_domain=gmail.com and auth_username=myemailID@gmail.com
    auth_password=mygmailpassword

    and also set
    force_sender=myemailID@gmail.com


    Next i modified my php.ini to
    [mail function]
    ; For Win32 only.
    ;SMTP = localhost
    ;smtp_port = 25

    ; For Win32 only.
    ;sendmail_from = me@example.com

    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t"

    ; Force the addition of the specified parameters to be passed as extra parameters
    ; to the sendmail binary. These parameters will always replace the value of
    ; the 5th parameter to mail(), even in safe mode.
    ;mail.force_extra_parameters =


    When I ran my mail() in PHP, it gives no errors. It seems to have run successfully but the actual email is never delivered to the specified inbox. So I checked the error.log of sendmail. It says " Socket Error # 10054<EOL>Connection reset by peer."

    What am I to do next?


    All I want to achieve is to send mail through PHP

  11. #11
    Ultimate Lifeform Nimrod's Avatar
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    1,991
    Blog Entries
    24

    Default

    An update to this thread, Google Mail has changed its SSL security and removed support for v2 which the Sendmail.exe used. I used a fix posted up on Google Groups by Aaron, and the problem was solved.

    As of March 14th, Google phased out SSLv2. Since, Byron Jones' fake
    sendmail application depended on it, all of us who were using it found
    out that it no longer worked.
    Here are step-by-step instructions to fix it. You need stunnel.
    1) Download and Install: http://www.stunnel.org/download/stun...-installer.exe
    2) In start menu, go to stunnel folder and click on 'Edit
    stunnel.conf'
    3) Copy the following into stunnel.conf and save.
    cert = stunnel.pem
    socket = l:TCP_NODELAY=1
    socket = r:TCP_NODELAY=1
    debug = 7
    output = stunnel.log
    client = yes
    [smtpg]
    accept = 127.0.0.1:25
    connect = smtp.gmail.com:465
    4) Run stunnel
    5) Go edit sendmail.ini and change to the following:
    smtp_server=localhost and smtp_port=25
    6) Restart GAE
    Hope this helps!
    -Nimrod

    Have a question or need help? Post on the forum, thats why it's here. I will only reply to Digiex related issues via PM, not general help requests.
    If I helped you can say thanks by signing up for Dropbox with my referral link, we will both get an extra 500mb of space for free.

  12. #12

    Default SSL is not available says error.log

    hello I downloaded sendmail configured it in a way you did. I used google smtp to do this. but got an error in error.log

    10.08.08 16:51:25 : SSL is not available on this server.

    any suggestion?

  13. #13
    Ultimate Lifeform Nimrod's Avatar
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    1,991
    Blog Entries
    24

    Default

    Quote Originally Posted by foilman View Post
    hello I downloaded sendmail configured it in a way you did. I used google smtp to do this. but got an error in error.log

    10.08.08 16:51:25 : SSL is not available on this server.

    any suggestion?
    Look above your post for the fix.....
    -Nimrod

    Have a question or need help? Post on the forum, thats why it's here. I will only reply to Digiex related issues via PM, not general help requests.
    If I helped you can say thanks by signing up for Dropbox with my referral link, we will both get an extra 500mb of space for free.

  14. #14

    Default stunnel does not work

    I configured stunnel changed the conf in sentmail.ini but did not work...did you work this program before?

  15. #15

    Smile S

    Quote Originally Posted by foilman View Post
    I configured stunnel changed the conf in sentmail.ini but did not work...did you work this program before?
    It works. (stunnel ) Thank You for that guide. Check weather all parameter set. look their is
    Code:
    [smtpg] 
    accept = 127.0.0.1:25 
    connect = smtp.gmail.com:465
    copy this code directly to stunnel.ini ... dont replace. there is parameter called [ssmtp]..
    u probably change 'accept' and 'connect' parameters on that......

  16. #16

    Default

    Quote Originally Posted by Nimrod View Post
    An update to this thread, Google Mail has changed its SSL security and removed support for v2 which the Sendmail.exe used. I used a fix posted up on Google Groups by Aaron, and the problem was solved.
    Thanks for Guide.. It works. Great !!!!!!!!!!!!!!!!!!!!!!

  17. #17

    Angry Error

    Help i keep getting this

    Warning: mail() [function.mail]: Could not execute mail delivery program 'C:\Inetpub\DOMAIN\Main\Sendmail\sendmail.exe -t'

    ve set the prmistion to all te fles nthe Sedmail folder toread an execude but it wont work?
    pleaee help

  18. #18
    Ultimate Lifeform Nimrod's Avatar
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    1,991
    Blog Entries
    24

    Default

    Quote Originally Posted by snazy2000 View Post
    Help i keep getting this

    Warning: mail() [function.mail]: Could not execute mail delivery program 'C:\Inetpub\DOMAIN\Main\Sendmail\sendmail.exe -t'

    ve set the prmistion to all te fles nthe Sedmail folder toread an execude but it wont work?
    pleaee help
    The variable is right, so thats solely a permission problem which I doubt I can help you with. Just make sure whatever user the web server and php are running in, has permission to execute sendmail.exe in the directory its in.
    -Nimrod

    Have a question or need help? Post on the forum, thats why it's here. I will only reply to Digiex related issues via PM, not general help requests.
    If I helped you can say thanks by signing up for Dropbox with my referral link, we will both get an extra 500mb of space for free.

  19. #19

    Default

    Even if i pout Everyone with full permition it still fails... :/ Please someone help!

  20. #20

    Default

    Fixed My problem! i added read and execute to cmd.exe in my system32 folder and works fine now Chears guys

  21. #21

    Default

    Quote Originally Posted by snazy2000 View Post
    Fixed My problem! i added read and execute to cmd.exe in my system32 folder and works fine now Chears guys
    Sorry for doing this :/ i does work but it dont send the email. It says in the script thats sent in the browser that its sent but i goto the imbox and its not there. If i do it with cmd it send the email how does this work.... help..

  22. #22

    Default

    Hi
    I used the gmail to set my PHP mail function. It shows email send out success, but actually I did not receive. Then I check PHP error log, there's nothing; then I check sendmail folder error, it shows "Connect timed out", how to fix it? Thank you

  23. #23

    Default

    I have followed the steps and am able to send email using our companies google apps account. Here is the issue. The emails are being sent with a time that is 7 hours old. I have checked the machine sending the emails and the time is correct GMT-7. When I adjust the machines time to being 7 hours ahead the emails show as being sent at the correct time. This is not a good solution for me as the software relies on the local time being accurate. Where can I adjust the timestamp? Here is an email message that arrived with a sent time as being 7 hours old.

    Received: from VM-SN-DEMO.ridgetopgroup.com ([74.94.94.113]) by mx.google.com with ESMTPS id k8sm495260yhm.73.2011.07.19.16.26.09 (version=SSLv3 cipher=RC4-MD5); Tue, 19 Jul 2011 16:26:10 -0700 (PDT) Message-ID: <4e261292.08b5ec0a.61c0.2a8c@mx.google.com> Date: Tue, 19 Jul 2011 16:26:07 +0000

  24. #24

    Default

    Quote Originally Posted by RGI_Matthew View Post
    I have followed the steps and am able to send email using our companies google apps account. Here is the issue. The emails are being sent with a time that is 7 hours old. I have checked the machine sending the emails and the time is correct GMT-7. When I adjust the machines time to being 7 hours ahead the emails show as being sent at the correct time. This is not a good solution for me as the software relies on the local time being accurate. Where can I adjust the timestamp? Here is an email message that arrived with a sent time as being 7 hours old.

    Received: from VM-SN-DEMO.ridgetopgroup.com ([74.94.94.113]) by mx.google.com with ESMTPS id k8sm495260yhm.73.2011.07.19.16.26.09 (version=SSLv3 cipher=RC4-MD5); Tue, 19 Jul 2011 16:26:10 -0700 (PDT) Message-ID: <4e261292.08b5ec0a.61c0.2a8c@mx.google.com> Date: Tue, 19 Jul 2011 16:26:07 +0000
    I have the same issue. The emails received have a time stamp that is 5 hours off but the PHP code inside the email is correct. I tried adjusting the PHP.ini date.timezone setting but this did nothing. I found some info on adjusting the sendmail.mc and .cf files but this seems only for a UNIX install as these files do not exist in the Windows version. Anyone else experience the issue and possibly know where to adjust the setting?

Similar Threads

  1. CF3B5's PS3 Proxy Server GUI for Windows - Download
    By Nimrod in forum Applications, Utilities and Homebrew (PS3/PC)
    Replies: 0
    Last Post: 02-08-14, 13:15
  2. Enable Push with Gmail on iPhone for free
    By Nimrod in forum Mobile Devices
    Replies: 0
    Last Post: 04-10-09, 12:17
  3. Gmail Servers Down? 24/02/2009
    By Nimrod in forum News and Article Submission
    Replies: 3
    Last Post: 24-02-09, 18:00
  4. Get in to the Windows 7 Home Premium / Server Beta
    By InsaneNutter in forum News and Article Submission
    Replies: 1
    Last Post: 16-01-09, 21:33
  5. Windows Vista and Server 2008 SP2 Beta Invites Sent Out
    By InsaneNutter in forum News and Article Submission
    Replies: 3
    Last Post: 26-10-08, 09:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Digiex is a technology and gaming forum, founded in 2004 by InsaneNutter and Nimrod. Digiex has served the internet community with breaking news, detailed guides, exclusive downloads and a popular discussion forum. A small, friendly community of like minded people has developed over the years. People are encouraged to register and participate in on-going discussions.
Join us