You are here

phpmailer.module in PHPMailer 5

This module integrates PHPMailer with Drupal, both as native drupal_mail() wrapper, and as part of the Mime Mail module.

File

phpmailer.module
View source
<?php

/**
 * @file
 * This module integrates PHPMailer with Drupal, both as native drupal_mail()
 * wrapper, and as part of the Mime Mail module.
 */

/**
 * Implementation of hook_perm().
 */
function phpmailer_perm() {
  return array(
    'administer phpmailer settings',
  );
}

/**
 * Implementation of hook_menu().
 */
function phpmailer_menu($may_cache) {
  $items = array();
  if ($may_cache && !module_exists('mimemail')) {
    $items[] = array(
      'path' => 'admin/settings/phpmailer',
      'title' => t('Mail'),
      'description' => t('Configure PHPMailer e-mail settings.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'phpmailer_settings_form',
      'access' => user_access('administer phpmailer settings'),
    );
  }
  return $items;
}
if (strpos(variable_get('smtp_library', ''), 'phpmailer') && !function_exists('drupal_mail_wrapper')) {

  /**
   * Implementation of drupal_mail_wrapper().
   *
   * @param $mailkey
   *   A key to identify the mail sent, for altering.
   * @param $to
   *   E-mail address to send to.
   * @param $subject
   *   Subject of e-mail.
   * @param $body
   *   Message body.
   * @param $from
   *   E-mail address of sender.
   * @param $header
   *   Array of additional header lines.
   */
  function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $header) {
    include_once drupal_get_path('module', 'phpmailer') . '/includes/phpmailer.inc';
    return phpmailer_send((array) $to, $subject, $body, $from, $header);
  }
}

/**
 * Implementation of hook_mailengine().
 */
function phpmailer_mailengine($op, $message = array()) {
  switch ($op) {
    case 'name':
      return t('PHPMailer');
    case 'description':
      return t('Mailing engine using PHPMailer.');
    case 'settings':
      require_once drupal_get_path('module', 'phpmailer') . '/phpmailer.admin.inc';
      return _phpmailer_settings_form();
    case 'multiple':
    case 'single':
    case 'send':
      include_once drupal_get_path('module', 'phpmailer') . '/includes/mimemail.inc';
      $defaults = array(
        'address' => '',
        'subject' => '',
        'body' => '',
        'sender' => '',
        'headers' => array(),
      );
      $message = array_merge($defaults, $message);
      settype($message['address'], 'array');
      $status = mimemail_phpmailer_send($message['address'], $message['subject'], $message['body'], $message['sender'], $message['headers']);
      return $status;
  }
  return FALSE;
}
function phpmailer_parse_address($address) {
  $regexp = "/^(.*) <([a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,})>\$/i";
  if (preg_match($regexp, $address, $matches)) {
    return array(
      'name' => trim($matches[1], '"'),
      'address' => $matches[2],
    );
  }
  return FALSE;
}

/**
 * Menu callback; Form builder for the module's settings page.
 */
function phpmailer_settings_form() {
  require_once drupal_get_path('module', 'phpmailer') . '/phpmailer.admin.inc';
  $form = _phpmailer_settings_form();
  return system_settings_form($form);
}

Functions

Namesort descending Description
phpmailer_mailengine Implementation of hook_mailengine().
phpmailer_menu Implementation of hook_menu().
phpmailer_parse_address
phpmailer_perm Implementation of hook_perm().
phpmailer_settings_form Menu callback; Form builder for the module's settings page.