WordPress Designpraxis Forum » BackUpWordPress Issues resolved

[closed] Fatal error: Cannot redeclare class phpmailer

(5 posts)

Tags:


  1. Saksoy
    Member

    I have the WP-EMail plugin installed and when I activate the BackupWordPress it interferes with it. This is the error message it gives when I try to click on the email this post link.

    Fatal error: Cannot redeclare class phpmailer in /homepages/30/d131350319/htdocs/wp-content/plugins/email/class-phpmailer.php on line 21

    For now I will just have to switch between the two to backup my site. Any ideas why?

    Great plugin, just wish the two would work simultaneously, so I can utilizes the automatic email backup.

    =================
    Roland Rust replied
    class-phpmailer.php is actually a class that comes with WordPress since version 2.2.0.
    On line 24 of wp-email.php, which is the main file of the WP-Email plugin you can find the require statement for that class.

    Add the following if-statement around it:
    if (class_exists('phpmailer')) {
    require(...);
    }

    you should also change the path to the file that comes with WordPress and use require_once instead of require.
    use: require_once(ABSPATH."wp-includes/class-phpmailer.php");

    Posted 2 years ago #
  2. Saksoy
    Member

    Thanks, for the help.

    I changed the first half but I did not understand the following:

    you should also change the path to the file that comes with WordPress and use require_once instead of require.
    use: require_once(ABSPATH."wp-includes/class- phpmailer.php");

    Can you clarify please? In which file do I change this?

    I will definitely mention this conflict and your fix to WP-Email.

    Thanks for you time and help.

    Posted 2 years ago #
  3. Saksoy, the require statement tells your plugin to load the contents of a specific file when running another. require_once ensures that a file ist loaded only once thus preventing an error.

    If all plugins, making use of class-phpmailer.php require the file which resides in the wp-includes path of the WordPress installation and do that by calling require_once, this file, holding the class phpmailer in fact is loaded only once when running any of these plugins.

    That's why BackUpWordPress requires the class-phpmailer that comes with WordPress.
    Another method would be to ask if that class exists allready: http://www.php.net/class_exists

    so the following code would have a similar effect:

    if (!class_exists("phpmailer")) {
    require_once(ABSPATH."wp-includes/class- phpmailer.php");
    }

    Put this instead of the require-line in wp-email.php and you'll be fine.

    Posted 2 years ago #
  4. Saksoy
    Member

    Yup, it worked thank you.

    Posted 2 years ago #
  5. ;) You're welcome!

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.