$message['from'], 'to' => $message['to'], 'subject' => $message['subject'], 'text' => check_plain($message['body']), 'html' => $message['body'], ); // Add CC, BCC and Reply-To fields if not empty. $headers = array_change_key_case($message['headers']); if (!empty($headers['cc'])) { $mailgun_message['cc'] = $headers['cc']; } if (!empty($headers['bcc'])) { $mailgun_message['bcc'] = $headers['bcc']; } if (!empty($headers['reply-to'])) { $mailgun_message['h:Reply-To'] = $headers['reply-to']; } $params = array(); // Populate default settings. if ($variable = variable_get('mailgun_tracking', 'default') != 'default') { $params['o:tracking'] = $variable; } if ($variable = variable_get('mailgun_tracking_clicks', 'default') != 'default') { $params['o:tracking-clicks'] = $variable; } if ($variable = variable_get('mailgun_tracking_opens', 'default') != 'default') { $params['o:tracking-opens'] = $variable; } // For a full list of allowed parameters, see: https://documentation.mailgun.com/api-sending.html#sending. $allowed_params = array('o:tag', 'o:campaign', 'o:deliverytime', 'o:dkim', 'o:testmode', 'o:tracking', 'o:tracking-clicks', 'o:tracking-opens'); foreach ($message['params'] as $key => $value) { // Check if it's one of the known parameters. $allowed = (in_array($key, $allowed_params)) ? TRUE : FALSE; // If more options become available but are not yet supported by the module, uncomment the following line. //$allowed = (substr($key, 0, 2) == 'o:') ? TRUE : FALSE; if ($allowed) { $params[$key] = $value; } // Check for custom MIME headers or custom JSON data. if (substr($key, 0, 2) == 'h:' || substr($key, 0, 2) == 'v:') { $params[$key] = $value; } } // Make sure the files provided in the attachments array exist. if (!empty($message['params']['attachments'])) { $params['attachments'] = array(); foreach ($message['params']['attachments'] as $attachment) { if (file_exists($attachment)) { $params['attachments'][] = $attachment; } } } $mailgun_message['params'] = $params; // Queue the message if the setting is enabled. if (variable_get('mailgun_queue', FALSE)) { $queue = DrupalQueue::get('mailgun_queue', TRUE); $queue->createItem($mailgun_message); return TRUE; } return mailgun_send($mailgun_message); } }