PHP mail sends but sender is always "Apache <apache@hosting12"

user1012032 picture user1012032 · Apr 17, 2012 · Viewed 15.4k times · Source

In my mail client or gmail the sender is always apache@hosting12

Any way to fix this issue? I have tried setting the headers like these with no success. Can sombody please help me?

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'$from'> \r\n";
$headers .= "Reply-To: <'$from'> \r\n";
$headers .= "Return-Path: <'$from'>\r\n";
$headers .= "X-Mailer: PHP \r\n";

or

$headers = "From: $from"; 

Answer

SequenceDigitale.com picture SequenceDigitale.com · Dec 3, 2012

I found that answer on a french forum. http://www.developpez.net/forums/d413965/php/outils/configuration-sendmail_path-sender/

You can add a 5th param to the mail function:

mail($mail_recipient, $subject, $message, $headers, '-f'.$mail_from);

Ths '-f' + mail_from force the system to send the email as the mail_from.