I have a custom module that sends an email, through SendGrid, to a mailing list. That list requires certain headers to be present in the email message. For example X-Something: Something
. These are not being set by the module when the message is built for SendGrid.
In my custom module's .module file I have
function thursday_mail($key, &$message, $params) {
$message['from'] = 'test@example.com';
$message['body'] = $params['body'];
$message['headers'] = [
'X-Testing' => 'just testing!',
'X-Mailer' => 'ThrusdayMail'
];
switch ($key) {
default:
$message['subject'] = 'DEFAULT: ' . $params['subject'];
}
}
When the email is delivered to my inbox, those headers are no longer in the message source.
In src/Plugin/Mail/SendGridMail.php, in the mail()
function, there is
// Beginning of consolidated header parsing.
foreach ($message['headers'] as $key => $value) {
switch (mb_strtolower($key)) {
That switch only looks for "content-type" and "reply-to" and ignores anything else. Any other headers are not added to $sendgrid_message
and disappear.
I propose adding the following to the bottom of the switch statement.
default:
$sendgrid_message->addHeader($key, $value);
In my testing, this does pass on the headers, and they are present in the message source when the email gets to my inbox.
If there's another way to accomplish the same thing, please let me know. Thank you!
Closed: outdated
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.