Results 1 to 10 of 10

Thread: PHP mail function and SMTP 501 error

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Posts
    228

    PHP mail function and SMTP 501 error

    Hi guys

    I have this mail function in PHP

    <code>

    function send_email ($recipient, $from, $reply_address, $subject, $message){

    ini_set('display_errors', '1');
    error_reporting(E_ALL);

    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= 'To:$recipient\r\n';
    $headers .= 'From:<$from>\r\n';
    //$headers .= 'Reply-To:$reply_address\r\n';


    if(!mail($recipient, $subject, $message, $headers)){
    return 'Mail function failed.';
    }

    else
    {
    return 'ok';
    }
    }

    </code>

    Whenever I call it it comes up with the next error:

    Warning: mail(): SMTP server response: 501 Syntax error in forward path in E:\apache2triad\htdocs\i2card.co.uk\functions\email_function.php on line 15


    From what I can understand, I made a mistake in setting up the header, but I am not sure which one is it.

    Could someone point me in the right direction please?
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    The "To:" header isn't needed as that's already taken care of by the mail function. It's wrong anyway as it should be "RCPT TO:". "From:" is wrong too, that should be "MAIL FROM:". See RFC 2821 for the correct header syntax.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  3. #3
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Quote Originally Posted by SirDice
    The "To:" header isn't needed as that's already taken care of by the mail function. It's wrong anyway as it should be "RCPT TO:". "From:" is wrong too, that should be "MAIL FROM:". See RFC 2821 for the correct header syntax.

    Thanks for your reply. I will go through the paper now.

    Tried the changes you advised, but the error still appears.

    Yet the function on top is derived from

    <code>

    function send_email($email,$format='text',$msg='',$subject='')
    }

    // send an email to the address $email in the format $format
    // with contents $msg and subject $subject


    global $fromname, $fromemail, $admin_email;

    if($format!='text' && $format!='html')
    {
    return 'Invalid mail format!';
    }
    $headers='';

    if($format=='html')
    {
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    }
    $headers .= "To: $email\r\n";
    $headers .= "From: WebSite Admin <$admin_email>\r\n";

    if(!mail($email, $subject, $msg, $headers))
    {
    return 'Mail function failed.';
    }
    else
    {
    return 'ok';
    }
    }

    </code>


    And that one is proven to be working fine on the other system. That is why I'm so confused

    It's been ages since I last wrote one of these.
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Could the fact that email functionality is not propely set up (i.e. sendmail_path),
    could that leat to the 501 error appearing?
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  5. #5
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188
    I am absolutely no expert in this area but this does look rather odd:

    ($email,$format='text',$msg='',$subject='')

    Are they the right way round?

  6. #6
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    OK, I got the function to work, but the e-mails are not arriving to the test address given.

    Any ideas?

    The problem was that the test server does not have "sendmail_path" setup
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  7. #7
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,188
    Any error or failure messages?

    Is the test address set up properly?

  8. #8
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Quote Originally Posted by nihil
    Any error or failure messages?

    Is the test address set up properly?
    There's no error message, and I'm sending it to my hotmail account, so that should work fine.
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  9. #9
    Senior Member
    Join Date
    Oct 2003
    Location
    MA
    Posts
    1,052
    well whats your new set of code?

  10. #10
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    Well turns out that the functions was perfectly fine.

    The mail function is called by a different one, the second person on the project made some changes to the variables and the function itself, but not in every necessary place, so the email was going through joined with the username

    like:

    un; nightcat
    em; email@server.com

    theyd come through as "email@server.comnightcat"

    I got it, only when I started printing out the variables one by one
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

Similar Threads

  1. Port List
    By ThePreacher in forum Miscellaneous Security Discussions
    Replies: 17
    Last Post: December 14th, 2006, 09:37 PM
  2. Web Buggery: Analyzing Tracking Images
    By Irongeek in forum The Security Tutorials Forum
    Replies: 8
    Last Post: April 27th, 2005, 04:44 PM
  3. Tutorial: Apache 2.0.49 and PHP 4.3.7!
    By Vorlin in forum Other Tutorials Forum
    Replies: 3
    Last Post: June 15th, 2004, 10:25 PM
  4. php mail function prob
    By journy101 in forum Newbie Security Questions
    Replies: 1
    Last Post: May 1st, 2003, 06:16 AM
  5. SMTP (Reach out and touch someone)
    By Sp1d3r-W0lf in forum The Security Tutorials Forum
    Replies: 0
    Last Post: December 27th, 2001, 05:31 PM

Posting Permissions

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