Re: PHP's mail(): proper way to send a 'From' header

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 7, 2008 at 1:50 PM, Jay Moore <jaymoore@xxxxxxxxxxxx> wrote:
> Greetings folks. I seem to be having a problem with PHP's mail() function
> and sending 'From' headers properly. Here's my setup:
>
[snip!]
>
> I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local
> ISPs) saying the sender's domain does not exist. It seems that either mails
> are coming from my hostname (nobody@xxxxxxxxxxxxxx), or those ISPs are
> reading the additional headers incorrectly. Unfortunately, this is not
> acceptable. People aren't getting their emails, and the hammer is coming
> down on me.

    Jay, try something like this:

<?php

$to = "email1@xxxxxxxxxxx";

$from = "email2@xxxxxxxxxxx";

$subject = "This is a test!";

$body  = "\tThis is a test email.\n";
$body .= "That is all.";

$headers  = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "X-Mailer: ".basename(__FILE__)."-PHP/".phpversion()."\r\n";
$headers .= "Return-Path: ".$from."\r\n";

mail($to,$subject,$body,$headers,'-f'.$from);
?>

    Note the fifth parameter passed to mail():

        http://php.net/mail

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux