Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.