How add List-Unsubscribe header to native mail() function of PHP

2.2k Views Asked by At

i've tested my spamscore on https://www.mail-tester.com/. It was good, but as an aprovement it suggested :

Your message does not contain a List-Unsubscribe header The List-Unsubscribe header is required if you send mass emails, it enables the user to easily unsubscribe from your mailing list.

How do I add this to a native mail(); function of PHP. Or is it even possible this way? (I cannot find one single simple example on the www).

1

There are 1 best solutions below

3
On BEST ANSWER

You can add additional headers with the mail() function.

$headers = [
    'From: [email protected]',
    'List-Unsubscribe: <mailto:[email protected]?subject=unsubscribe>'
];

$body = 'I am the newsletter content.';

mail('[email protected]', 'Subject of newsletter', $body, implode("\r\n", $headers));