【问题标题】:PHP How to prevent mail from leaking script and IP in headerPHP如何防止邮件在标头中泄漏脚本和IP
【发布时间】:2021-07-31 10:00:36
【问题描述】:

我正在使用 PHPMailer 发送电子邮件。

在电子邮件的原始消息中,标题包含

X-PHP-Script: /path/to/my/script.php myip6address, myip4address

我在php.ini中编辑了这些设置

[mail function]
mail.add_x_header = 0
add_x_header = 0

在我的php脚本中,当我使用ini_get("mail.add_x_header")时,它返回"0"

// to try and erase the info from the global server var
$_SERVER = Array();

$mail = new PHPMailer;
$mail->setFrom("me@mysite.com");
$mail->addAddress("foo@gmail.com");

// to try and override it, instead it just appends and keeps the original header
$mail->addCustomHeader("X-PHP-Script", "No.");
$mail->Subject = "This is a test";
$mail->isHTML(true);
$mail->Body = "hello world";

if($mail->send() == false)
{
    var_dump("failed to send mail", $mail->ErrorInfo);
}

它仍然会在我发送的每封电子邮件中发送我的脚本位置和我的 IP 地址。

如果我使用 mail() 而不是 PHPMailer,它也会发送它,但我假设 PHPMailer 在后台使用 mail()

如何完全禁用该标头?

【问题讨论】:

    标签: php email header phpmailer email-headers


    【解决方案1】:

    我不确定为什么您的 ini 设置没有抑制它。 PHPMailer 确实默认使用mail(),但您应该尝试使用 SMTP 到 localhost,因为它比mail() 更快更安全,并且可以让您控制所有标头。您所要做的就是:

    $mail->isSMTP();
    

    默认设置应该没问题。

    【讨论】:

    • 我最终使用IsSendMail() 来使用sendmail.exe 而不是mail(),但如果有mail() 的解决方案会很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 2011-07-04
    • 2011-09-30
    • 2010-12-20
    相关资源
    最近更新 更多