Created
February 13, 2019 14:37
-
-
Save joshfeck/cffccb7ca8a8bca82b9851f2e01b2d20 to your computer and use it in GitHub Desktop.
Fixes the mandrill's silent discard of cc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fixes the mandrill's silent discard of cc. | |
*/ | |
//first add filter to EE's email process to modify `cc:` header to `x-cc` so it gets past the initial mandrill header setup. | |
add_filter('FHEE__EE_Email_messenger___headers', function($headers) { | |
foreach ($headers as $header) { | |
if (strpos($header, 'cc: ') !== false) { | |
$headers[] = 'x-cc: ' . str_replace('cc: ', '', $header); | |
} | |
} | |
return $headers; | |
}, 5); | |
//next capture the x-cc from the header and add it to the `to` array (with type set as 'cc') then remove the special | |
// `x-cc` header. | |
add_filter('mandrill_payload', function($payload){ | |
if (isset($payload['headers'], $payload['headers']['x-cc'])) { | |
$cc_emails = $payload['headers']['x-cc']; | |
unset($payload['headers']['x-cc']); | |
$cc_emails = explode(',', $cc_emails); | |
$cc_emails = array_map('trim', $cc_emails); | |
foreach($cc_emails as $cc) { | |
$payload['to'][] = array( | |
'email' => $cc, | |
'type' => 'cc' | |
); | |
} | |
} | |
return $payload; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment