PHP邮件发送,但发送者始终是" Apache

时间:2012-04-17 01:11:39

标签: php email sender

在我的邮件客户端或Gmail中,发件人始终是apache @ hosting12

有什么方法可以解决这个问题吗? 我试过像这样设置标题但没有成功。 sombody请帮帮我?

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

$headers = "From: $from"; 

3 个答案:

答案 0 :(得分:7)

我在法国论坛上找到答案。 http://www.developpez.net/forums/d413965/php/outils/configuration-sendmail_path-sender/

您可以在邮件功能中添加第5个参数:

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

's'-f'+ mail_from强制系统将邮件作为mail_from发送。

答案 1 :(得分:4)

标题中有额外的单引号。试试这样:

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

您也可以删除不必要的“回复”和“回复路径”。

答案 2 :(得分:1)

请从$from左右删除单引号并使用{$from}

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

或者您可以使用以下签名来传递from

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

修改

您还想检查sendmail_from文件中的php.ini设置。