PHP邮件:-f是做什么的?


PHP mail: What does -f do?

在对一个带有电子邮件主机的联系表单进行故障排除时,他们告诉我在php邮件函数的from地址中使用'-f'。"-f"标志的作用是什么,为什么它是允许发送电子邮件的修复?我读了一些文档,但我不是很清楚。

示例代码:

mail($emailAddress, $mailSubject, $mailBody, $headers, '-f ' . $mailFrom);

PS:没有"-f",对于大型电子邮件主机(hotmail, gmail等,但无论出于何种原因,不适合我正在使用的小型主机)

谢谢

-f是邮件发送器(通常是sendmail)的参数。来自文档:

additional_parameters参数可用于传递附加参数标志为配置为要使用的程序的命令行选项当发送邮件时,由sendmail_path配置定义设置。例如,这可以用来设置信封发送者

下面是sendmail的手册页,您可以看到-f选项的作用:

-fname           Sets the name of the ``from'' person (i.e., the sender of the
                 mail).  -f can only be used by ``trusted'' users (normally
                 root, daemon, and network) or if the person you are trying to
                 become is the same as the person you are.

-f选项用于设置反弹邮件地址。发送没有一个的消息会对根据该消息计算的垃圾邮件得分产生负面影响。分数低的消息有时会被某些主机过滤掉。

您可以使用https://www.mail-tester.com/测试您的消息的分数。您可以尝试使用或不使用-f标志并查看分数变化。

标记以下文本($mailFrom)作为邮件的"from"地址。

请看:http://www.php.net/manual/en/function.mail.php