messaging_phpmailer.module in Messaging 5
HTML Mail using PHPMailer. Messaging method plug-in.
File
messaging_phpmailer/messaging_phpmailer.moduleView source
<?php
/**
* @file
* HTML Mail using PHPMailer. Messaging method plug-in.
*/
/**
* Implementation of hook_messaging
*/
function messaging_phpmailer_messaging($op = 'info') {
switch ($op) {
case 'send methods':
$info['html_mail'] = array(
'name' => t('HTML Mail'),
'group' => 'mail',
'destination' => 'mail',
'send' => 'messaging_phpmailer_send_msg',
'type' => MESSAGING_TYPE_PUSH,
'glue' => "<br>",
// don't use <br/> nor <br /> for maximum HTML email client compatibility
'footer' => "<br><br>--",
'description' => t('Send HTML e-mails using PHPMailer'),
);
return $info;
}
}
/**
* Send mail message to user account. Supports bulk sending
*
* @param $destination
* Single email address
* @param $message
* Message array
*/
function messaging_phpmailer_send_msg($destination, $message, $params = array()) {
$params = messaging_mail_params($message, $params);
return messaging_phpmailer_drupal_mail($params['mailkey'], $destination, $message['subject'], $message['body'], $params['from'], $params['headers']);
}
/**
* Send a message via PHPMailer.
* This function mimics drupal_mail. We do not use drupal_mail instead because we want
* to be able to send mail with both PHPMailer and MIMEMail.
*/
function messaging_phpmailer_drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) {
include_once './' . drupal_get_path('module', 'messaging_phpmailer') . '/PHPMailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail
->IsSMTP();
// telling the class to use SMTP
$mail->CharSet = 'utf-8';
$mail->ContentType = 'text/html';
// Uncomment the following line to get debug information printed out during mail sends
//$mail->SMTPDebug = TRUE;
$host = variable_get('messaging_phpmailer_smtp_server', ini_get('SMTP'));
if ($host) {
$mail->Host = $host;
// SMTP server
}
else {
watchdog('messaging', t('SMTP server cannot be reached.'), WATCHDOG_ERROR);
return FALSE;
}
// Theme the mail message
list($subject, $body) = theme('messaging_phpmailer', $subject, $body, $from, $mailkey);
// To prevent e-mail from looking like spam, the addresses in the Sender and
// Return-Path headers should have a domain authorized to use the originating
// SMTP server. Errors-To is redundant, but shouldn't hurt.
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
if ($default_from) {
$defaults['From'] = $defaults['Reply-To'] = $defaults['Sender'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $default_from;
}
if ($from) {
$defaults['From'] = $defaults['Reply-To'] = $from;
}
$headers = array_merge($defaults, $headers);
// Custom hook traversal to allow pass by reference
foreach (module_implements('mail_alter') as $module) {
$function = $module . '_mail_alter';
$function($mailkey, $to, $subject, $body, $from, $headers);
}
$mail->From = $defaults['From'];
$mail->FromName = $defaults['From'];
$mail
->AddAddress($to);
if (!empty($headers['Message-ID'])) {
$mail
->AddCustomHeader('Message-ID: ' . $headers['Message-ID']);
}
if (!empty($headers['Reply-To'])) {
$mail
->AddReplyTo($headers['Reply-To']);
}
// Strip HTML out of $body for plaintext equivalent of HTML email.
$mail->AltBody = messaging_html_to_text($body);
// The subject has been already filtered by messaging module
$mail->Subject = $subject;
$mail->Body = str_replace("\r", '', $body);
return $mail
->Send();
}
/**
* default theme messaging_phpmailer
*/
function theme_messaging_phpmailer($subject, $body, $from, $mailkey) {
return array(
$subject,
$body,
);
}
Functions
Name | Description |
---|---|
messaging_phpmailer_drupal_mail | Send a message via PHPMailer. This function mimics drupal_mail. We do not use drupal_mail instead because we want to be able to send mail with both PHPMailer and MIMEMail. |
messaging_phpmailer_messaging | Implementation of hook_messaging |
messaging_phpmailer_send_msg | Send mail message to user account. Supports bulk sending |
theme_messaging_phpmailer | default theme messaging_phpmailer |