简体   繁体   English

PHP 如何防止邮件泄漏 header 中的脚本和 IP

[英]PHP How to prevent mail from leaking script and IP in header

I'm using PHPMailer to send out an email.我正在使用 PHPMailer 发送一个 email。

In the raw message of the email, the header contains在 email 的原始消息中,header 包含

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

I edited into the php.ini these settings我将这些设置编辑到 php.ini

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

In my php script, when I use ini_get("mail.add_x_header") , it returns "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);
}

It still sends my scripts location and my IP address with every email I send.它仍然会发送我的脚本位置和我的 IP 地址以及我发送的每个 email。

It also sends it if I use mail() instead of PHPMailer, but I assume PHPMailer uses mail() under the hood.如果我使用mail()而不是 PHPMailer,它也会发送它,但我假设 PHPMailer 在后台使用mail()

How can I disable that header entirely?如何完全禁用 header?

Im not sure why your ini settings are not suppressing that.我不确定为什么您的 ini 设置没有抑制它。 PHPMailer does indeed use mail() by default, but you should try using SMTP to localhost instead as it's both faster and safer than mail() , and will give you control over all the headers. PHPMailer 确实默认使用mail() ,但是您应该尝试使用 SMTP 来代替 localhost ,因为它比mail()更快更安全,并且可以让您控制所有标题。 All you have to do is:你所要做的就是:

$mail->isSMTP();

And the default settings should be fine.默认设置应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM