Skip to content

Adding Custom Headers (List-Unsubscribe, List-Id, etc.)

edited April 2013 in Suggestions

This is based on lessons learned in this post: http://forum.sendy.co/discussion/750/list-unsubscribe-header

Amazon SES accespts a number of custom header fields (http://docs.aws.amazon.com/ses/latest/DeveloperGuide/header-fields.html)

For sending to GMail users in particular, the List-Unsubscribe header is useful for allowing automatic unsubscribe requests, while the List-Id header is useful for helping recipients auto-filter your messages, but this approach can be used to add any customer headers you wish.

List-Unsubscribe Header

Because we wanted to include some values from Sendy's custom fields in our headers, here's an example of how we did it. Assuming each list member has a unique customer ID in Custom Field 2, and we want to include that in an unsubscribe request, we need to add the following line to whichever sending script you're using (/sendy/includes/create/send-now.php if you don't use a cron job to manage your sends, or /sendy/scheduled.php if you do).

Look for the $mail->AddReplyTo($reply_to, $from_name); line. Add a new line underneath, such as this one:

$mail->AddCustomHeader("List-Unsubscribe: <mailto:unsubscribe@example.com?subject=".$email."+".$custom_values_array[2].">,<http://example.com/unsubscribe/?email=".$email."&id=".$custom_values_array[2].">");

That example allows GMail to automatically send a message to the unsubscribe@example.com address if a user clicks "This is Spam" or chooses Unsubscribe from one of the option menus. Note that the message includes both the email and user ID number in the subject. Including both can help you confirm legitimate unsubscribe requests and filter our random unsub requests with only an email address. Note that the ?subject must be included with the address in the header in order to GMail to display the unsubscribe link.

List-Id Header

After the first custom line above, we also added this line:

$mail->AddCustomHeader("List-Id: Newsletter Name <newsletter.example.com>");

This adds a function for GMail users to auto-filter your newsletter.

Google "List-Unsubscribe" and "List-Id" for more info.

Comments

  • Hi Steve,

    You added $mail->AddCustomHeader("List-Id: ... and after it you added $mail->AddCustomHeader("List-Unsubscribe ?

    Thanks,
    Adrian

  • It's working. Great job Steve! (Y)

  • Hi,

    I have added this below code in /scheduled.php and /includes/create/send-now.php

    $mail->AddCustomHeader("List-Unsubscribe: <mailto:unsubscribe@login.360emailsperhour.com?subject=".$email."+".$custom_values_array[2].">,<http://login.360emailsperhour.com/unsubscribe/?email=".$email."&id=".$custom_values_array[2].">");
    

    $mail->AddCustomHeader("List-Id: Newsletter Name <newsletter.login.360emailsperhour.com>");

    I am still not able to get the header unsubscription URL in GMail. I am using custom SMTP for sending Emails.

    Please help

    Regards,
    Shirish

  • I expected List-Unsubscribe-Header in 1.1.9.4 as Sendy's releasenotes states: Added 'List-Unsubscribe' header (unsubscribe URL as value) to emails sent as 'campaigns' and 'autoresponders'. I sent a test to Gmail but couldn't find it. Am I looking in the wrong place?

  • Gmail decides whether to include 'unsubscribe' at the top. They have an algorithm to detect if an email looks like a newsletter, if it does then it will place the unsubscribe link at the top.

  • Hi Ben,

    Can you please suggest ways on how can we have unsubscribe button ( List Unsubscribe Header ) on top of our mails.

    I have recently moved from Mail chimp - and all the emails send via it had this link.

    If there is an algorithm used by gmail to put this in, can you please suggest the best possible way on getting this done ?

    This is important for email marketing and this will help us maintain our mailing lists clean as well.

    Please let us know.

  • BenBen
    edited September 2014

    Hi @Sherfur,

    Please see this taken from http://blog.mailchimp.com/gmails-new-unsubscribe-link-and-feedback-loop/

    That's exactly the inconsistency I'm seeing right now.

    Thanks.

    Best regards,
    Ben

This discussion has been closed.