Answers.Body: <p>The hook_civicrm_alterMailParams(&amp;$params, $context) hook is called twice</p>
  <ol>
  <li>$context == 'messageTemplate' -&gt; When building the message, at this moment the toEmail is not set</li>
  <li>$context == 'singleEmail' -&gt; called when email is build and about to send.</li>
  </ol>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-22T13:59:42.983Z
Answers.Text: Thank you so much... I simply forgot about that and made a change in my own code that did not respect that fact. Sorry for the noise!
Answers.UserDisplayName: Tobias Krause
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-22T10:16:13.330Z
Answers.LastActivityDate: 2022-06-22T10:16:13.330Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>In our development environment I redirect mails following some specific rules. I am quite sure that I achieved that in the past with <code>hook__civicrm_alterMailParams</code> where I changed the <code>$params['toEmail']</code> to whatever email suited. Additionally I changed <code>$params['text']</code>to have some info about the original email address.</p>
  <p>Now this logic starts to fail after upgrading from CiviCRM 5.50.0 to 5.50.2 (when you send a mail to an individual contact from the contact view page). The reason is that <code>$params['toEmail]</code> has now the value <code>NULL</code> instead of a string with the email address. For sending mass mailings this logic still works - for every single email the hook is called with an $params array with 'toEmail' set.</p>
  <p>The release notes from 5.50.1 and 5.50.2 did not show any code changes that seem to be related to that. How can I find someone to check that? It seems to be a main issue to me when changes like that are made in core without any information.</p>
  
Tags: <civimail><hooks><core>
Title: Changes in hook__civicrm_alterMailParams not respected anymore when sending mails to individual contacts
ThreadText: # Changes in hook__civicrm_alterMailParams not respected anymore when sending mails to individual contacts
  
  (Asked by: username_0 on 2022-06-22)
  
  In our development environment I redirect mails following some specific rules. I am quite sure that I achieved that in the past with `hook__civicrm_alterMailParams` where I changed the `$params['toEmail']` to whatever email suited. Additionally I changed `$params['text']`to have some info about the original email address.
  
  Now this logic starts to fail after upgrading from CiviCRM 5.50.0 to 5.50.2 (when you send a mail to an individual contact from the contact view page). The reason is that `$params['toEmail]` has now the value `NULL` instead of a string with the email address. For sending mass mailings this logic still works - for every single email the hook is called with an $params array with 'toEmail' set.
  
  The release notes from 5.50.1 and 5.50.2 did not show any code changes that seem to be related to that. How can I find someone to check that? It seems to be a main issue to me when changes like that are made in core without any information.
  
  **Tags:** civimail, hooks, core
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-22. Score: 1 | Accepted answer
  
  The hook\_civicrm\_alterMailParams(&$params, $context) hook is called twice
  
  1. $context == 'messageTemplate' -> When building the message, at this moment the toEmail is not set
  2. $context == 'singleEmail' -> called when email is build and about to send.
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: Thank you so much... I simply forgot about that and made a change in my own code that did not respect that fact. Sorry for the noise!  
  
  ---
  
  