View source
<?php
define('POSTMARKAPP_API_KEY', variable_get('postmark_api_key', ''));
if (module_load_include('php', 'postmark', 'includes/Postmark')) {
drupal_set_message('You must include the Postmark PHP5 library to use this module. See README.txt for more details.', 'error');
}
function postmark_send($message) {
static $mail;
if (!isset($mail)) {
$mail = new Mail_Postmark();
}
$address = postmark_parse_address($message['from']);
$mail
->from($address[0]['mail']);
if ($address[0]['name'] != '') {
$mail
->fromName($address[0]['name']);
}
unset($message['headers']['From']);
$debug_mode = variable_get('postmark_debug_mode', 0);
$debug_email = variable_get('postmark_debug_email', '');
if (!$debug_mode) {
foreach (postmark_parse_address($message['to']) as $id => $address) {
if ($id == 0) {
$mail
->to($address['mail'], $address['name']);
}
else {
$mail
->addTo($address['mail'], $address['name']);
}
}
}
else {
if ($debug_email != '') {
drupal_set_message(t('Debugging email used @email', array(
'@email' => $debug_email,
)), 'warning');
$mail
->to($debug_email);
}
}
$mail
->subject($message['subject']);
if (strpos($message['headers']['Content-Type'], 'text/plain') !== FALSE) {
$mail
->messagePlain($message['body']);
}
else {
$mail
->messageHtml($message['body']);
}
if (isset($message['headers']['Reply-To'])) {
$reply_to = postmark_parse_address($message['headers']['Reply-To']);
$mail
->replyTo($reply_to[0]['mail'], $reply_to[0]['name']);
}
if ($debug_mode) {
drupal_set_message('Message array: <pre>' . print_r($message, TRUE) . '</pre>', 'warning');
}
if (variable_get('postmark_debug_no_send', 0)) {
drupal_set_message('Email successfully tested, no email has been sent (no credits used)', 'warning');
return TRUE;
}
else {
try {
if (!($result = $mail
->send())) {
watchdog('postmark', "Mail sending error: {$mail->ErrorInfo}", NULL, WATCHDOG_ERROR);
}
} catch (Exception $e) {
watchdog('postmark', 'Exception message: ' . $e
->getMessage(), NULL, WATCHDOG_ERROR);
drupal_set_message('Mail sending error: ' . $e
->getMessage(), 'error');
if ($debug_mode) {
watchdog('postmark', 'Exception caught: <pre>' . print_r($e, TRUE) . '</pre>', NULL, WATCHDOG_ERROR);
}
}
}
return $result;
}