How to hide set from mail on php mail
When sending an email using PHP's mail()
function, you can hide the Set-Cookie
headers by setting the P3P
header in your email. Here's an example:
$headers = array(
'From' => '[email protected]',
'Subject' => 'Test Email',
'P3P' => 'CP="NOI ADM DEV PSAi COM NAV OUR STP MIE SAM OTRo STPo DES DEVa TMT ENG TEA STA PRE"',
);
mail('[email protected]', 'Test Email', 'Hello, world!', $headers);
The P3P
header is a way to specify the privacy policy of your website, and by setting it to CP="NOI ADM DEV PSAi COM NAV OUR STP MIE SAM OTRo STPo DES DEVa TMT ENG TEA STA PRE"
, you're telling the email client that your website does not set cookies.
However, please note that this method is not foolproof, as some email clients may still display the Set-Cookie
headers even with the P3P
header set.
Alternatively, you can use a PHP library like SwiftMailer
or PHPMailer
which provide more advanced features for sending emails, including the ability to hide cookies.
Here's an example using SwiftMailer
:
$mailer = new Swift_Mailer(new Swift_SendmailTransport());
$message = Swift_Message::newInstance('Test Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody('Hello, world!')
->setContentType('text/plain');
$message->getHeaders()->addTextHeader('P3P', 'CP="NOI ADM DEV PSAi COM NAV OUR STP MIE SAM OTRo STPo DES DEVa TMT ENG TEA STA PRE"');
$mailer->send($message);
And here's an example using PHPMailer
:
$mail = new PHPMailer();
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]');
$mail->Subject = 'Test Email';
$mail->Body = 'Hello, world!';
$mail->addCustomHeader('P3P', 'CP="NOI ADM DEV PSAi COM NAV OUR STP MIE SAM OTRo STPo DES DEVa TMT ENG TEA STA PRE"');
$mail->send();
Keep in mind that hiding cookies may not be necessary or desirable in all cases, and you should carefully consider the implications of doing so.