4

I'm using PHPMailer to send out an email.

In the raw message of the email, the header contains

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

I edited into the php.ini these settings

[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".

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

$mail = new PHPMailer;
$mail->setFrom("[email protected]");
$mail->addAddress("[email protected]");

// 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.

It also sends it if I use mail() instead of PHPMailer, but I assume PHPMailer uses mail() under the hood.

How can I disable that header entirely?

0

1 Answer 1

0

Im not sure why your ini settings are not suppressing that. 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. All you have to do is:

$mail->isSMTP();

And the default settings should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

I ended up using IsSendMail() to use sendmail.exe instead of mail(), but it would be nice if there was a solution for mail()
@John If you are already using PHPMailer, why do you need a solution for mail()?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.