Jump to content

Getting mail() to work


geraldmpiper

Recommended Posts

I'm doing some work on a client's server - how can I be sure that mail() will work?  I'm using it in code, and I'm not getting any error messages, but I'm not getting any email through.

    $to = '[email protected]';
    $from = '[email protected]';
    $bcc = '[email protected]';
    $subject = 'Test';
    $message = 'This is a test.';
    $headers = "From: Myname <$from>\r\n";
    $headers .= "BCC: $bcc\r\n";
//leave the next 2 lines alone
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if(mail($to, $subject, $message, $headers))
{
    echo "<br>Mail sent";
    }
    else
{
    echo "<br>Mail send failure - message not sent";
    }

Link to comment
https://forums.phpfreaks.com/topic/46787-getting-mail-to-work/
Share on other sites

www.php.net/mail

 

Look at the mail function and notice the [email protected] Try that, some servers require the -f to function properly, IE:

 

if (mail($to, $subject, $message, $headers, '[email protected]')) {
    print "Sent Succesfully";
}

 

Also a side note, I found on my server, if mail returns false it does not always mean the mail was not sent. I think this is was reported on php.net bug list but I am unsure. Just be wary that the mail may not always return what you expect it to.

Link to comment
https://forums.phpfreaks.com/topic/46787-getting-mail-to-work/#findComment-228053
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.