1

I know i'm doing something stupid here, but I can't figure it out. I'm sending an email using the following:

    $headers  = "MIME-Version: 1.0
    From: ".$from_email."
    Bcc: ".$bcc_email."
    ";
    mail($email, $message['subject'], $message['content'], $headers);

where $from_email = 'no-reply@mydomain.com'

The message is coming through with the wrong from address. full headers below:

 Return-path: <cli@hostxxx.com>
Envelope-to: xxx@email.com
Delivery-date: Tue, 20 Nov 2012 11:01:34 -0500
Received: from cli by cli@hostxxx.com with local (Exim 4.69)
    (envelope-from <cli@hostxxx.com>)
    id 1TaqGI-000232-IJ
    for xxx@email.com; Tue, 20 Nov 2012 11:01:26 -0500
To: xxx@email.com
Subject: Fairway Solutions - Your new password
MIME-Version: 1.0
        From: no-reply@mydomain.com
        Bcc: support@mydomain.com
Message-Id: <E1TaqGI-000232-IJ@host.com>
From: cli@hostxxx.com
Date: Tue, 20 Nov 2012 11:01:22 -0500

Annoyingly, i can see the From coming through correctly, but it's like the received is overwriting with the hosts' info. Am I missing something at a server level?

I've also tried setting it in the php.ini file (ini_set(sendmail_from,no-reply@mydomain.com);) and it's made no difference.

ta

TH1981
  • 3,105
  • 7
  • 42
  • 78
  • Related: http://stackoverflow.com/questions/179014/how-to-change-envelope-from-address-using-php-mail http://stackoverflow.com/questions/2229435/how-do-i-set-the-from-address-in-a-php-contact-form – twodayslate Nov 20 '12 at 16:14
  • I usually use PHPMailer to send emails from PHP scripts, it's very easy to use ^^ – Naryl Nov 20 '12 at 16:15

1 Answers1

2

You might try adding addition headers such as the X-Sender:

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= "From: $sender<" . $sender . ">" . "\r\n";
$headers .= "X-Sender: $sender<" . $sender . ">" . "\n";
$headers .= "X-Mailer: PHP " . phpversion() . "\n";
$headers .= "X-Priority: 3" . "\n";
$headers .= "X-Sender-IP: " . $_SERVER['REMOTE_ADDR'] . "\n";
$headers .= "Return-Path: $sender<" . $sender . ">" . "\r\n";
$headers .= "Reply-To: $sender<" . $sender . ">" . "\r\n"; 
Samuel Cook
  • 16,620
  • 7
  • 50
  • 62
  • trying now. stupid question: is there a reason for seperating the `$headers` to different lines? I ask because i have a 50/50 success rate on the mail client reading the `\r\n` correctly – TH1981 Nov 20 '12 at 16:17
  • I think it does make a difference in how the email is parsed by the mail client, I don't honestly know though. It is how php.net displays their sample code. – Samuel Cook Nov 20 '12 at 16:19
  • thanks. adding the extra headers has worked, though it does still show the host name in the received info in the headers, it's not overwriting the from anymore. ta – TH1981 Nov 20 '12 at 16:22
  • You might need to modify the headers to get what you need – Samuel Cook Nov 20 '12 at 16:24
  • Side note: adding the `Content-type: text/html; charset=iso-8859-1` header affected the body layout and took out my line breaks and formatting. Still worked with everything else as is, so we're good - just in case anyone else has this happen :D – TH1981 Nov 20 '12 at 16:27