Joe Schmoe
Joe Schmoe

Reputation: 1

PHP - Not Sending Emails with Header Information

I am having a problem sending emails when I add header information. However when I just remove the header parameter it works. What is wrong? Is it the code? Or some setting I need to change on the web server admin panel to say "Allow-Headers" or something? I am trying to send to hotmail in case this has any relavance in determining the problem. Any help would be greatly appreciated. Thanks.

Below Doesn't Send Email:

<?php

    $to      = '[email protected]';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: [email protected]';

    mail($to, $subject, $message, $headers);

?>

Below Sends Email:

<?php

    $to = '[email protected]';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: [email protected]';

    mail($to, $subject, $message);

?>

Upvotes: 0

Views: 162

Answers (2)

Mohammed Anwar
Mohammed Anwar

Reputation: 59

You can just delete the "FROM:" from the headers list .. it prevents it in some hosts .But the real question then will be how ca I change the sent from email address to a specific email that I want

Upvotes: 0

Chris
Chris

Reputation: 7288

I use these headers in my php mailing function and it works well. Note: I also use a third party mail-routing service to avoid having my mails marked as coming from a spammy IP. You might want to look into that also.

$headers = 'From: '.$from.'@foo.net' . "\r\n" .
'Reply-To: '.$from.'@foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";

I also use the optional fifth parameter to mail() to set the envelope address, e.g.:

$parameters = '-f '.$from.'@foo.net';

so the final call is:

mail($to, $subject, $message, $headers, $parameters);

Upvotes: 1

Related Questions