Skip to content
Snippets Groups Projects
Commit 9d761c7e authored by Daniel Kudwien's avatar Daniel Kudwien
Browse files

Issue #1183820 by sun: Allow sending test mail without globally enabling PHPMailer.

parent dc17a39d
No related branches found
No related tags found
No related merge requests found
PHPMailer 7.x-3.x, xxxx-xx-xx PHPMailer 7.x-3.x, xxxx-xx-xx
----------------------------- -----------------------------
#1183820 by sun: Allow sending test mail without globally enabling PHPMailer.
#971172 by sun, Shaun Dychko: Clarify Google Apps support. #971172 by sun, Shaun Dychko: Clarify Google Apps support.
#811774 by sun, elliotttf: Ported to Drupal 7. #811774 by sun, elliotttf: Ported to Drupal 7.
......
...@@ -137,8 +137,31 @@ function phpmailer_settings_form($form_state) { ...@@ -137,8 +137,31 @@ function phpmailer_settings_form($form_state) {
if ($test_address = variable_get('phpmailer_test', '')) { if ($test_address = variable_get('phpmailer_test', '')) {
// Delete first to avoid unintended resending in case of an error. // Delete first to avoid unintended resending in case of an error.
variable_del('phpmailer_test'); variable_del('phpmailer_test');
drupal_mail('phpmailer', 'test', $test_address, NULL); // If PHPMailer is enabled, send via regular drupal_mail().
drupal_set_message(t('A test e-mail has been sent to %email. <a href="@watchdog-url">Check the logs</a> for any error messages.', array('%email' => $test_address, '@watchdog-url' => url('admin/reports/dblog')))); if (phpmailer_enabled()) {
drupal_mail('phpmailer', 'test', $test_address, NULL);
}
// Otherwise, prepare and send the test mail manually.
else {
// Prepare the message without sending.
$message = drupal_mail('phpmailer', 'test', $test_address, NULL, array(), NULL, FALSE);
// Send the message. drupal_mail_wrapper() is only defined when PHPMailer
// is enabled, so drupal_mail_send() cannot be used.
// @see drupal_mail_send()
module_load_include('inc', 'phpmailer', 'includes/phpmailer.drupal');
$message['result'] = phpmailer_send($message);
// Log errors
// @see drupal_mail()
if (!$message['result']) {
watchdog('mail', 'Error sending e-mail (from %from to %to).', array('%from' => $message['from'], '%to' => $message['to']), WATCHDOG_ERROR);
drupal_set_message(t('Unable to send e-mail. Please contact the site administrator if the problem persists.'), 'error');
}
}
drupal_set_message(t('A test e-mail has been sent to %email. <a href="@watchdog-url">Check the logs</a> for any error messages.', array(
'%email' => $test_address,
'@watchdog-url' => url('admin/reports/dblog'),
)));
} }
$form['test'] = array( $form['test'] = array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment