php - PHP如何防止邮件在标头中泄漏脚本和IP
问题描述
我正在使用 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 地址。
如果我使用而不是 PHPMailer,它也会发送它mail()
,但我假设 PHPMailermail()
在后台使用。
如何完全禁用该标头?
解决方案
我不确定为什么您的 ini 设置没有抑制它。默认情况下确实使用 PHPMailer mail()
,但您应该尝试使用 SMTP 到 localhost,因为它比 SMTP 更快更安全mail()
,并且可以让您控制所有标头。你所要做的就是:
$mail->isSMTP();
默认设置应该没问题。
推荐阅读
- javascript - 从 JSON 数据格式化分组数据
- c# - UWP-xaml InkCanvas:有没有办法拒绝在特定区域上绘画?
- python - Comparing Two Lines In Opened Files With For Loops
- angular - Angular: Reset Array without reloading view in Ui
- zapier - Why doesn't my Zapier Integration Dynamic Field work?
- cucumber - Cucumber testng 与 PowerMockTestCase 模拟静态类
- powershell - Change a property of a task in task scheduler using powershell
- amazon-web-services - AWS 负载均衡器和 BlueHost
- c++ - Zero initialization of nested struct - compiler bug?
- c# - IReadOnlyList
and setter