我一直包含 -f
在我的 php 应用程序中标记,因为我认为它很重要,正如文档告诉我们的那样:
The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.
所以看起来它是用来防止欺骗的 - 通过验证我是谁。然后我做了一个实验。事实证明,如果我不包含-f,我发送邮件时仍然不会出现X-Warning。事实上,发件人甚至不需要是我自己。例如,我尝试了 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d022f2c202c0d3a252439282522383e2863223f2a" rel="noreferrer noopener nofollow">[email protected]</a>
作为发件人,我收到了电子邮件,没有任何警告。我什至尝试使用 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d624f4c404c6d5a454459484542585e4803425f4a" rel="noreferrer noopener nofollow">[email protected]</a>
向多个电子邮件帐户发送数百封电子邮件,并且它们没有被标记为垃圾邮件。
所以,我的问题是,-f
是什么? flag 真的可以吗(因为在我看来,没有它,电子邮件也能正常发送)?
最佳答案
-f 标志用于指定信封发件人
地址。您应该使用 -f 标志来设置此地址,以便它与邮件 header 中的 FROM
地址相匹配,否则某些垃圾邮件过滤器更有可能将邮件视为垃圾邮件两者不匹配。
您可以执行如下操作来设置两者,以使它们匹配:
$to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681c07281c07460b0705" rel="noreferrer noopener nofollow">[email protected]</a>";
$from = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f392d30321f392d3032713c3032" rel="noreferrer noopener nofollow">[email protected]</a>";
$subject = "subject";
$message = "this is the message body";
$headers = "From: $from";
$ok = @mail($to, $subject, $message, $headers, "-f " . $from);
关于php - PHP 邮件中我们真的需要 -f 标志吗?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29039977/