Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post

    Thumbs up sendmail binary to send email with PHP on Windows

    Hi,

    I believe I require the sendmail binary to be able to send an email automatically from my local machine? How is this done? I don't see it under the "extensions" in the PHP installer?

    Picco

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    In the class.phpmailer.php script, there is a variable
    var $Sendmail = "/usr/sbin/sendmail -t -i ";
    When I set this path to my sendmail.exe, it will start a command-prompt when I submit my form, but I'm not sure whether it'll send mail.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by crmpicco View Post
    Hi,

    I believe I require the sendmail binary to be able to send an email automatically from my local machine? How is this done? I don't see it under the "extensions" in the PHP installer?

    Picco
    You set it in the php.ini. For example XAMPP provides it as:
    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:\xampp\sendmail\sendmail.exe -t"
    Or you can use the SMTP settings instead.

  • #4
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    Hi guys, the second pah you highlighted there was unix only bythe looks of it. I am on WinXP Home. I commented the sendmail_from line back in and my [mail function] block now looks like:

    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 =
    
    ; 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 =
    If this all seems correct how would I send an email in PHP? I was simply using mail() before.

    Picco

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    The PHP dev team put "For Unix only" because the sendmail binary is not native to Windows, but if you have it installed you can just set the path there. Otherwise you can just use SMTP to send mail.

  • #6
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    Ok, that's great. i'll try changing the path to the sendmail.exe I have downloaded. I take it that any time PHP tries to send an email it will use sendmail? The reason I am asking is I have a forum setup locally to go along with my site and when I tried to register a new user (and send an auto email) it error'd when sending the mail.

    NB. Forum software PHPBB2.

    Picco

  • #7
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    i've now changed the PHP ini file to be:
    Code:
    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    sendmail_from = info~NOSPAMPLEASE~@ayrshireminis.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = C:\sendmail\sendmail.exe
    
    ; 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 =
    I ran a simple script that sent an email and thats all it done, it took a few seconds (maybe 7-10) to run but I thought that was a good sign. As you can see from my PHP.ini file it is sending from "info~NOSPAMPLEASE~@ayrshireminis.com" (the ~NOSPAMPLEASE~ isn't actually in the file). Do i have to have authentication in the file for this email to work?

    I have tried to send a mail to an @aol.co.uk address and a @hotmail.com one, but neither email has come through.

    Picco

  • #8
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    tried changing the script to:

    PHP Code:
    mail("crmpicco~NOSPAM~@hotmail.com""MESSAGE""Hi from website");
    mail("crmpicco~NOSPAM~@aol.co.uk""MESSAGE""Hi from website"); 
    Neither came through to either acount using the sendmail.exe - is there anything else I can try?

    Picco

  • #9
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    To get a receiving mail server to accept an email, you either need to 1) send it from a properly configured public mail server (with a domain name, a DNS server, proper DNS records), 2) send it from an email client that uses SMTP authentication against a mail box on the receiving mail server, or 3) you need a mail server that does not require SMTP authentication because it "trusts" the IP address of the email client (or it is open to relaying.)

    For case #1 above, since you don't have a public mail server setup on your localhost development system, this method is not available.

    For case #3 above, this is the normal situation on a web host with PHP (not using the Unix sendmail binary) and a mail server. When the php mail() function is being used this way it acts like an SMTP email client that is not using SMTP authentication (it in fact does not support SMTP authentication.) The mail server trusts the IP address of the web server and it accepts mail sent by php scripts using the mail() function.

    For case #2, above, where you are attempting to send an email to or through a remote email server. The only way you will be able to get this to work is if you use SMTP authentication. What this means is you must supply a username/mail box name and the corresponding password for that mail box. This is exactly what you do when you setup an email client, like Outlook, to send mail.

    I suspect that the sendmail.exe program you found is simply emulating the Unix sendmail binary but it operates as an SMTP email client as far as the receiving mail server is concerned. If you post a link to where you found the sendmail.exe program it is possible that someone can help. However, unless it has settings that let you authenticate against a mail box, it is unlikely that you will be able to get a mail server to accept an email from it.

    As already mentioned, the php mail() function does not support SMTP authentication. If the sendmail.exe program you found will not do this for you, you will need to use something like the phpmailer class. The good news is that once you get your code working using the phpmailer class, it only requires that the settings be changed when you move your code to an actual web host.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #10
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    Thanks for your reply, it was helpful. I had a script recommended to me and I was pointed towards the PHP Mailer SourceForge project - the code I am now using is:

    PHP Code:
    <?php
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host "mail.ayrshireminis.com";  // specify main and backup server
    //$mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username "myuser@name.co.uk";  // SMTP username
    $mail->Password "mypasswordinhere"// SMTP password

    $mail->From "info@ayrshireminis.com";
    $mail->FromName "Mailer";
    $mail->AddAddress("crmpicco~NOSPAM~@~NOSPAM~hotmail.com");
    //$mail->AddAddress("crmpicco~NOSPAM#@hotmail.com");                  // name is optional
    $mail->AddReplyTo("info#getspamtohell#@ayrshireminis.com""Information");

    $mail->WordWrap 50;                                 // set word wrap to 50 characters
    //$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
    $mail->IsHTML(true);                                  // set email format to HTML

    $mail->Subject "Here is the subject";
    $mail->Body    "This is the HTML message body <b>in bold!</b>";
    $mail->AltBody "This is the body in plain text for non-HTML mail clients";

    if(!
    $mail->Send())
    {
       echo 
    "Message could not be sent. <p>";
       echo 
    "Mailer Error: " $mail->ErrorInfo;
       exit;
    }

    echo 
    "Message has been sent";
    ?>
    "class.phpmailer.php" is quite a big script, so I won't spam the forum with it. But it is on SourceForge - http://phpmailer.sourceforge.net/

    It seems to log-in ok, and it sends an email fine to the info~NOSPAM~@ayrshireminis.com address from that address but errors when I try a hotmail.com or an aol.co.uk one.

    I got my details for my login from: http://www.awardspace.com/web_hosting_faq.html

    AwardSpace do not support SMTP.

    Picco
    Last edited by crmpicco; 10-05-2007 at 07:40 PM. Reason: email addresses

  • #11
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    Please Note: I Scrapped the mail() idea as you kind of mentioned....... :-) don't think it's going to work here!!!!! Picco

  • #12
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    but errors when I try a hotmail.com or an aol.co.uk one.
    What error are you getting as it would probably help pin down exactly what the problem is?

    To use the authentication settings, add the following line -
    Code:
    $mail->SMTPAuth = true;
    With that setting off/missing, authentication is not on. Without authentication, your mail server is more than happy to accept an email from a PHP script when the To: address is hosted on your mail server, but it won't relay emails to an outside mail system.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #13
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    sorry, the error is:

    Code:
    Message could not be sent.
    
    Mailer Error: Language string failed to load: recipients_failed
    crmpiccoNAESPAM@hotmail.com
    I commented that code back in now and tried the hotmail.com address. Even though it states SMTP Authenication does this still apply for the POP3 server I am trying to send email through?

  • #14
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post
    there must be something I can do with my php.ini file to allow it to send an email. I am trying to create some new accounts through my forum (PHPBB2), however it fails when it tries to send an email.

    Has anyone had this problem before? Is there a way to get around it?

    Picco


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •