Which if it is, this error is thrown:

Fatal error: Cannot redeclare class phpmailerException in /home/path/to/website/sites/all/modules/smtp/phpmailer/class.phpmailer.php on line 2319

To fix this, just change around line 266 to look like the following:

  // Include the PHPMailer class (which includes the SMTP class).
  if (!class_exists('PHPMailer')) {
    require_once(drupal_get_path('module', 'smtp') .'/phpmailer/class.phpmailer.php');
  }

Comments

kyle_mathews’s picture

--- IGNORE -- Pasted wrong function.

kyle_mathews’s picture

I'd also suggest adding a phpmailer_load function which can check in the libraries directory as well as in a subdirectory. This is a function I wrote for OG Mailinglist, borrowed mostly untouched from messaging_phpmailer.


function og_mailinglist_phpmailer_load_library() {
  if (!class_exists('PHPMailer')) {
    // First, try using libraries module.
    if (module_exists('libraries')) {
      // Let's see if PHPMailer is really available from libraries.
      $phpmailer_library = './'. libraries_get_path('PHPMailer') .'/class.phpmailer.php';
      if (file_exists($phpmailer_library)) {
        include_once $phpmailer_library;
      }
    }
    // If PHPMailer is not already loaded, then try from module subdirectory.
    if (!class_exists('PHPMailer')) {
      $phpmailer_library = './'. drupal_get_path('module', 'og_mailinglist') .'/PHPMailer/class.phpmailer.php';
      if (file_exists($phpmailer_library)) {
        include_once $phpmailer_library;
      }
    }
  }
  // Tell the caller if PHPMailer class exists.
  return class_exists('PHPMailer');
}
Simon Georges’s picture

Status: Active » Closed (duplicate)

I think it's a duplicate of #541942: Move PHPMailer out of the module folder, check for class already defined. As there is a patch on that issue, I'm closing this one.