Download & Extend

SMTP doesn't check if PHPMailer class is already loaded

Project:SMTP Authentication Support
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

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:

<?php
 
// 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

#1

--- IGNORE -- Pasted wrong function.

#2

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.

<?php
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');
}
?>

#3

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.

nobody click here