phpfunctionemailnativelist-unsubscribe

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


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


Solution

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

    $headers = [
        'From: thisisme@example.net',
        'List-Unsubscribe: <mailto:thisisme@example.net?subject=unsubscribe>'
    ];
    
    $body = 'I am the newsletter content.';
    
    mail('recipent@example.net', 'Subject of newsletter', $body, implode("\r\n", $headers));