array(
'title' => t('Administer PHPMailer settings'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook_menu().
*/
function phpmailer_menu() {
$items['admin/config/system/phpmailer'] = array(
'title' => 'PHPMailer',
'description' => 'Configure PHPMailer settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('phpmailer_settings_form'),
'access arguments' => array('administer phpmailer settings'),
'file' => 'phpmailer.admin.inc',
);
// @todo Move to Mime Mail project.
$items['phpmailer/preview'] = array(
'title' => 'Mail preview',
'page callback' => 'phpmailer_preview',
'access callback' => 'phpmailer_preview_access',
'file' => 'phpmailer.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function phpmailer_form_mimemail_admin_settings_alter(&$form, &$form_state) {
// Hide the Mime Mail global enabler setting if phpmailer is used to deliver
// e-mails (they can't be both active).
if (phpmailer_enabled()) {
$mimemail_alter = &$form['mimemail']['mimemail_alter'];
$mimemail_alter['#disabled'] = TRUE;
$mimemail_alter['#default_value'] = 0;
$mimemail_alter['#description'] = t('PHPMailer has been set to deliver all site messages. To let Mime Mail apply styles and formatting to system e-mails but still use PHPMailer for mail transport, uncheck Use PHPMailer to send e-mails first on the PHPMailer settings page. Then activate this setting and choose PHPMailer from the list of e-mail engines below.', array('@url' => url('admin/config/system/phpmailer')));
}
// @todo Move to MimeMail project.
$form['preview'] = array(
'#type' => 'item',
'#title' => t('Preview'),
'#value' => t('See a preview of a styled e-mail using the current message template (mimemail-message.tpl.php
).', array('@url' => url('phpmailer/preview'))),
);
$form['buttons']['#weight'] = 10;
}
/**
* Determine if PHPMailer is used to deliver e-mails.
*/
function phpmailer_enabled() {
// We need to rely on our 'smtp_on' variable, since PHPMailer may not be
// configured as the default mail system.
return (bool) variable_get('smtp_on', 0);
}
/**
* Implements hook_mailengine().
*/
function phpmailer_mailengine($op, $message = array()) {
if (!phpmailer_library_exists()) {
return;
}
switch ($op) {
case 'list':
return array(
'name' => t('PHPMailer'),
'description' => t('Mailing engine using the PHPMailer library.'),
);
case 'settings':
$form['info']['#markup'] = t('To configure your mail server settings, visit the PHPMailer settings page.', array('@url' => url('admin/config/system/phpmailer')));
return $form;
case 'multiple':
case 'single':
case 'send':
module_load_include('inc', 'phpmailer', 'includes/phpmailer.mimemail');
// Mimemail API does not load mimemail.inc for other mailengines; we rely
// on mimemail_rfc_headers(), so ensure that it is loaded.
module_load_include('inc', 'mimemail');
return mimemail_phpmailer_send($message);
}
}
/**
* Extract address and optional display name of an e-mail address.
*
* @param string $string
* A string containing one or more valid e-mail address(es) separated with
* commas.
*
* @return array
* An array containing all found e-mail addresses split into mail and name.
*
* @see http://tools.ietf.org/html/rfc5322#section-3.4
*/
function phpmailer_parse_address($string) {
$parsed = array();
// The display name may contain commas (3.4). Extract all quoted strings
// (3.2.4) to a stack and replace them with a placeholder to prevent
// splitting at wrong places.
$string = preg_replace_callback('(".*?(?.*)\s<(?P