Get answers quicker by searching

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Adding Custom Headers (List-Unsubscribe, List-Id, etc.)
  • Vote Up0Vote Down SteveJSteveJ
    Posts: 16Sendy user

    This is based on lessons learned in this post:

    Amazon SES accespts a number of custom header fields (

    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: <".$email."+".$custom_values_array[2].">,<".$email."&id=".$custom_values_array[2].">");

    That example allows GMail to automatically send a message to the 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 <>");

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

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

  • Vote Up0Vote Down knz777knz777
    Posts: 7Sendy user

    Hi Steve,

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

    Thanks, Adrian

  • Vote Up0Vote Down knz777knz777
    Posts: 7Sendy user

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

  • Vote Up0Vote Down cshirishcshirish
    Posts: 1Sendy user


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

    $mail->AddCustomHeader("List-Unsubscribe: <".$email."+".$custom_values_array[2].">,<".$email."&id=".$custom_values_array[2].">");

    $mail->AddCustomHeader("List-Id: Newsletter Name <>");

    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 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?

  • Vote Up0Vote Down BenBen
    Posts: 3,667Sendy support

    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.

  • Vote Up0Vote Down BenBen
    Posts: 3,667Sendy support

    Hi @Sherfur,

    Please see this taken from

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


    Best regards,

This discussion has been closed.
All Discussions