Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created February 13, 2019 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/cffccb7ca8a8bca82b9851f2e01b2d20 to your computer and use it in GitHub Desktop.
Save joshfeck/cffccb7ca8a8bca82b9851f2e01b2d20 to your computer and use it in GitHub Desktop.
Fixes the mandrill's silent discard of cc.
/**
* 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