Commit 01d7f316 authored by smk-ka's avatar smk-ka

by smk-ka: Improved integration with Mime Mail.

parent ad6ef369
......@@ -2,6 +2,7 @@
PHPMailer 6.x-3.x, xxxx-xx-xx
-----------------------------
by smk-ka: Improved integration with Mime Mail.
by smk-ka: Removed bogus call to hook_mail_alter() from phpmailer_preview().
by smk-ka: Display a warning message if PHPMailer is disabled.
......
......@@ -59,18 +59,21 @@ Optional:
-- CONFIGURATION --
* Configure user permissions at Administer >> User management >> Access control
>> phpmailer module.
* Configure user permissions at Administer >> User management >> Access
control >> phpmailer module.
Only users with the "administer phpmailer settings" permission will gain
access to the module configuration page.
Only users with the "administer phpmailer settings" permission are allowed to
access the module configuration page.
* When not using the optional Mime Mail module, customize module settings at
Administer >> Site configuration >> PHPMailer.
* Configure your SMTP server settings at Administer >> Site
configuration >> PHPMailer.
If used in conjunction with Mime Mail, PHPMailer will show up as an e-mail
engine in the Mime Mail module settings. Note that there will be no separate
PHPMailer configuration page in this case.
engine in the Mime Mail module settings. 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 "Use mime mail for all messages" on the Mime Mail
settings page and choose PHPMailer from the list of available e-mail engines.
* Using Google Mail as SMTP server
......@@ -118,8 +121,4 @@ Authors:
* Stefan M. Kudwien (smk-ka) - http://drupal.org/user/48898
* Daniel F. Kudwien (sun) - http://drupal.org/user/54136
This project has been sponsored by UNLEASHED MIND
Specialized in consulting and planning of Drupal powered sites, UNLEASHED
MIND offers installation, development, theming, customization, and hosting
to get you started. Visit http://www.unleashedmind.com for more information.
This project has been sponsored by UNLEASHED MIND.
......@@ -14,29 +14,21 @@
* @see phpmailer_settings_form_submit()
*/
function phpmailer_settings_form($form_state) {
if (module_exists('mimemail') && $_GET['q'] == 'admin/settings/phpmailer') {
// Redirect to Mime Mail settings page instead.
drupal_goto('admin/settings/mimemail');
}
// Only enable the 'send all e-mails' option if Mime Mail is not configured
// the same (mimemail_alter is the counterpart to smtp_on).
if (!module_exists('mimemail') || !variable_get('mimemail_alter', 0)) {
$form['smtp_on'] = array(
'#type' => 'checkbox',
'#title' => t('Use PHPMailer to send e-mails'),
'#default_value' => variable_get('smtp_on', 0),
'#description' => t('When enabled, PHPMailer will be used to deliver all site e-mails.'),
);
if (!variable_get('smtp_on', 0) && empty($form_state['post']['smtp_on'])) {
drupal_set_message(t('PHPMailer is currently disabled.'), 'warning');
}
$form['smtp_on'] = array(
'#type' => 'checkbox',
'#title' => t('Use PHPMailer to send e-mails'),
'#default_value' => variable_get('smtp_on', 0),
'#description' => t('When enabled, PHPMailer will be used to deliver all site e-mails.'),
);
// Only allow to send all e-mails if Mime Mail is not configured the same
// (mimemail_alter is the counterpart to smtp_on).
if (module_exists('mimemail') && variable_get('mimemail_alter', 0)) {
$form['smtp_on']['#disabled'] = TRUE;
$form['smtp_on']['#default_value'] = 0;
$form['smtp_on']['#description'] = t('MimeMail has been detected. To enable PHPMailer for mail transport, go to the <a href="@url">MimeMail settings page</a> and select PHPMailer from the available e-mail engines.', array('@url' => url('admin/settings/mimemail')));
}
else {
$form['smtp_on'] = array(
'#type' => 'value',
'#value' => 0,
);
elseif (!variable_get('smtp_on', 0) && empty($form_state['post']['smtp_on'])) {
drupal_set_message(t('PHPMailer is currently disabled.'), 'warning');
}
$form['server']['smtp_host'] = array(
......@@ -162,19 +154,6 @@ function phpmailer_settings_form($form_state) {
'#default_value' => '',
'#description' => t('Type in an address to have a test e-mail sent there.'),
);
if (module_exists('mimemail')) {
$form['test']['preview'] = array(
'#type' => 'item',
'#title' => t('Preview'),
'#value' => t('For theming of HTML mails sent via Mime Mail, you can <a href="@preview-url" target="_blank">preview an example mail</a>.', array('@preview-url' => url('phpmailer/preview'))),
);
}
if (module_exists('mimemail')) {
return $form;
}
$form['#submit'] = array('phpmailer_settings_form_submit');
return system_settings_form($form);
}
......@@ -239,6 +218,7 @@ function phpmailer_mail($key, &$message, $params) {
/**
* Menu callback; Render a HTML mail preview in the browser.
* @todo Move to Mime Mail project.
*/
function phpmailer_preview() {
global $user;
......
......@@ -25,6 +25,7 @@ function phpmailer_menu() {
'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',
......@@ -35,17 +36,6 @@ function phpmailer_menu() {
return $items;
}
/**
* Implementation of hook_menu_alter().
*/
function phpmailer_menu_alter(&$items) {
// Hide the settings page menu item if Mime Mail is enabled, but still allow
// accessing the URL for usability reasons.
if (module_exists('mimemail')) {
$items['admin/settings/phpmailer']['_visible'] = FALSE;
}
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
......@@ -53,15 +43,18 @@ 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()) {
$form['mimemail']['mimemail_alter'] = array(
'#type' => 'value',
'#value' => 0,
);
$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 <em>Use PHPMailer to send e-mails</em> first on the <a href="@url">PHPMailer settings page</a>. Then activate this setting and choose PHPMailer from the list of e-mail engines below.', array('@url' => url('admin/settings/phpmailer')));
}
// Run our own validation and submit handler before Mime Mail to be able to
// detect configuration changes.
$form['#validate'] = array_merge(array('phpmailer_settings_form_validate'), (array)$form['#validate']);
$form['#submit'] = array_merge(array('phpmailer_settings_form_submit'), (array)$form['#submit']);
// @todo Move to MimeMail project.
$form['preview'] = array(
'#type' => 'item',
'#title' => t('Preview'),
'#value' => t('See a <a href="@url" target="_blank">preview of a styled e-mail</a> using the current message template (<code>mimemail-message.tpl.php</code>).', array('@url' => url('phpmailer/preview'))),
);
$form['buttons']['#weight'] = 10;
}
/**
......@@ -93,8 +86,8 @@ function phpmailer_mailengine($op, $message = array()) {
return t('Mailing engine using the PHPMailer library.');
case 'settings':
module_load_include('inc', 'phpmailer', 'phpmailer.admin');
return phpmailer_settings_form();
$form['info']['#value'] = t('To configure your mail server settings, visit the <a href="@url">PHPMailer settings page</a>.', array('@url' => url('admin/settings/phpmailer')));
return $form;
case 'multiple':
case 'single':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment