PHP mail script fails with no return code

Discussion in 'PHP' started by 0xpf, Jul 31, 2007.

  1. #1
    $ret = mail($to, $subject, $body, $headers);
    if ($ret)
    {
    echo "sent\n";
    } else {
    echo "failed with code $ret\n";
    }
    echo "done\n"

    I am trying to invoke this via apache, the call to mail fails immediately, and there is no return value, and so, I am stuck. Can you please point me in the right direction to debug this ?

    Thanks much
     
    0xpf, Jul 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    mail() returns either true of false, and echoing false won't give you any output.

    But the mail() function should trigger an error if it fails. If you don't see it, your error reporting is probably set to hide errors or warnings.

    Try this.

    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    echo mail($to, $subject, $body, $headers) ? 'sent' : 'failed';
    
    PHP:
     
    nico_swd, Aug 1, 2007 IP
  3. 0xpf

    0xpf Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply.

    It still displays no error at all. Any idea why that would be the case?

    Thanks.
     
    0xpf, Aug 1, 2007 IP
  4. Sygon

    Sygon Peon

    Messages:
    439
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Are you sure the mail host on your hosting is enableD?
     
    Sygon, Aug 1, 2007 IP