Re: PHP's mail(): proper way to send a 'From' header
| From: | Daniel Brown | Date: | Mon, 07 Jul 2008 18:13:49 +0000 |
| Subject: | Re: PHP's mail(): proper way to send a 'From' header | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276389@lists.php.net to get a copy of this message | ||
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.