Re: PHP's mail(): proper way to send a 'From' header
| From: | Eric Butera | Date: | Mon, 07 Jul 2008 18:17:01 +0000 |
| Subject: | Re: PHP's mail(): proper way to send a 'From' header | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276390@lists.php.net to get a copy of this message | ||
On Mon, Jul 7, 2008 at 2:13 PM, Daniel Brown <parasane@gmail.com> wrote:
> On Mon, Jul 7, 2008 at 1:50 PM, Jay Moore <jaymoore@accu-com.com> 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@web.mysite.com), 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@example.com";
>
> $from = "email2@example.org";
>
> $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
>
>
Yep! Just a note on this though. You have to control the domain
you're forcing the return-path on or else it will get rejected by a
lot of servers because of SPF rules. It has bit my company in the
behind quite a bit recently. :)