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 6 of 6

Thread: mail() woes

  1. #1
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts

    Question mail() woes

    I'm trying to figure out why the following code doesn;t send an email:

    PHP Code:
      // Mail password.
      
    $body "Dear $firstname: \n\nYou are receiving this e-mail because you have requested a copy of your YourCompany.com username and password.\n\n \tUsername: ".$username."\n \tNew Password: ".$new_pass."\n\nAfter you log in with your new password, you may change your password to something else. \n\nThank you! \n\n  - Staff";
      
    $subject "YourCompany.com: Lost Password";
      
    $headers "From: Admin<admin@domain.com>\r\n";
      
    //  echo $email . "<br>";
    //  echo $subject . "<br>";
    //  echo $body . "<br>";
    //  echo $headers . "<br>";
    //  die();
      
      
    if (mail($email$subject$body$headers))
      {  
       
    $errors .= '<br /><span>Your password has been e-mailed to you.</span>';
      }
      else
      {
       
    $errors .= '<br /><span>E-mail failed. Please contact Administrator for assistance.</span>';
      } 
    The variables appear to print out correctly (when the code is uncommented), and currently the text "Your password has been e-mailed to you." prints out to the screen.

    This is the phpinfo page.

    I've tried different variations of the "From:" header, and substituted variables in mail() with simple strings. Nothing seems to work with that code.

    Interestingly, when I execute the following code in a file by itself:

    PHP Code:
    <?
    $headers 
    "From: Admin<admin@domain.com>\r\n";
    mail("email@domain.com""TEST""THIS IS A TEST"$headers);
    ?>
    The code seems to work -- sometimes.

    I must be missing something somewhere. Can anyone help? If you need me to post more code, I can.

    Thanks.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #2
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Try seperating the from name (Admin) and the email address, ie

    Admin <admin@domain.com>

    instead of

    Admin<admin@domain.com>

    Spamassasin blocks emails without spaces between the name and email address

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by deamonlizard View Post
    Try seperating the from name (Admin) and the email address, ie

    Admin <admin@domain.com>

    instead of

    Admin<admin@domain.com>

    Spamassasin blocks emails without spaces between the name and email address
    Thanks, that didn't seem to help though. Any other ideas?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    change headers/subject?

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,773
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by rafiki View Post
    change headers/subject?
    The following code does not work:

    PHP Code:
    <? 
    $headers 
    "From: Admin <admin@domain.com>\r\n";
    mail("user@yahoo.com""TEST1""THIS IS TEST #1"$headers); 
    mail("user@yahoo.com""TEST2""THIS IS TEST #2"); 
    ?>
    Neither e-mail is sent. God knows why.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Who is your webhost? Many free hosts disable the smtp server.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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