Pergunta

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"; 
Foi útil?

Solução

Please remove single quotation mark from around $from and use {$from}

$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";

or you can use following signatures to pass from

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

EDIT:

You also want to check sendmail_from setting in php.ini file.

Outras dicas

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.

There are extra single quotes in your header. Try like this:

$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";

Also you can remove the unnecessary "Reply-To" and "Return-Path".

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top