Answers.Body: <p>thanks to @pradpnayak for guidance :D</p>
  
  <p>according to the docs for hook_civicrm_alterMailParams:</p>
  
  <blockquote>
    <p>You can add custom headers by appending to $params['headers']. Example:</p>
  
  <pre><code>$params['headers']['X-My-Header'] = 'my header value';
  </code></pre>
    
    <p>The headers key may not exist in the $params array when passed into the > hook.</p>
  </blockquote>
  
  <p>so this was the code in an extension to unset the existing 'List-Unsubscribe', and put in a NULL replacement into the headers:</p>
  
  <pre><code>/**
   * Implements hook_civicrm_alterMailParams().
   *
   * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
   */
  function custom_civicrm_alterMailParams(&amp;$params, $context) {
    if ($context == 'flexmailer' || $context == 'civimail') {
      // remove existing header
      unset($params['List-Unsubscribe']);
      // replace via the 'headers' key
      $params['headers']['List-Unsubscribe'] = NULL;
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-20T12:36:34.720Z
Answers.LastActivityDate: 2020-02-20T12:36:34.720Z
Answers.UserDisplayName: Marsh
Body: <p>There is a "header" entry automatically put into mailnigs from civimail (also when using flexmailer / mosaico) which some email clients use to enable unsubscribing (or opting out) from mailing lists.</p>
  
  <p>If, for example, an unsubscribe link is in your email, and the site is reporting opt-out's (or vice-versa) then this may be the reason why. So - how to fix it? </p>
  
Tags: <civimail><extension><php>
Title: Removing "List-Unsubscribe" from civimail headers (for when getting seemingly random unsubscribes)
ThreadText: # Removing "List-Unsubscribe" from civimail headers (for when getting seemingly random unsubscribes)
  
  (Asked by: username_0 on 2020-02-20)
  
  There is a "header" entry automatically put into mailnigs from civimail (also when using flexmailer / mosaico) which some email clients use to enable unsubscribing (or opting out) from mailing lists.
  
  If, for example, an unsubscribe link is in your email, and the site is reporting opt-out's (or vice-versa) then this may be the reason why. So - how to fix it?
  
  **Tags:** civimail, extension, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-02-20. Score: 2
  
  thanks to @pradpnayak for guidance :D
  
  according to the docs for hook\_civicrm\_alterMailParams:
  
  > You can add custom headers by appending to $params['headers']. Example:
  >
  > ```
  > $params['headers']['X-My-Header'] = 'my header value';
  >
  > ```
  >
  > The headers key may not exist in the $params array when passed into the > hook.
  
  so this was the code in an extension to unset the existing 'List-Unsubscribe', and put in a NULL replacement into the headers:
  
  ```
  /**
   * Implements hook_civicrm_alterMailParams().
   *
   * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
   */
  function custom_civicrm_alterMailParams(&$params, $context) {
    if ($context == 'flexmailer' || $context == 'civimail') {
      // remove existing header
      unset($params['List-Unsubscribe']);
      // replace via the 'headers' key
      $params['headers']['List-Unsubscribe'] = NULL;
    }
  }
  
  ```
  
  
  ---
  
  