• Hey guys,

    i wrote a simple Plugin for sending mails over the cronjob.
    WP_CRON is disabled and outsourced to crontabs on the server, for example:

    * * * * * /usr/bin/php5 -f /homepages/23/d471228603/htdocs/wp-cron.php >> /homepages/23/d471228603/htdocs/cron.log

    Here is the source: https://pastebin.com/tA4JgEBC

    Description:
    For testing, i use the direct-link to wp-cron on my Browser (for example: https://domain.com/wp-cron.php)

    When i use the wp_mail function first time, i become an PHP Error:

    Fatal error: Cannot redeclare class phpmailerException in /homepages/23/d471228603/htdocs/wp-includes/class-phpmailer.php on line 2825

    After reloading the page will be blank/white. The printing of display_name and email of the users will be not printed.

    Can anyone tell me why this does not work?

    I would like to use WordPress-own functions and needs wp_mail here.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Patrick

    (@hovida)

    SAME Problem is on wp-login.php?action=lostpassword

    maximinime

    (@maximinime)

    This one got me, too. I think it’s some kind of internal PHP bug, not your usual noob double-including mistake. Searching the web, everybody else’s problem was failing to use only require_once, or having two different copies of the file with different names or paths. I found a different cause and solution.

    The reason I think it’s internal to PHP is because:

    1. I verified that there was only one file defining that class in the entire project.
    2. I know that file was only being included once because I put if (class_exists('phpmailerException')) die('HOLY CRAP'); at the top of it. So it could not be included/required more than once without me knowing.
    3. I wrapped only the phpmailerException definition in a
      if (!class_exists('phpmailerException')) {...} block, which solved the problem!

    If the file was being included more than once, it would die with a fatal error as soon as it tried to define the main PHPMailer class again, but it never did. The only conclusion I could arrive at was that PHP was compiling the class twice in the same file.

    maximinime

    (@maximinime)

    It’s definitely some PHP weirdness. require_once is allowing the file to be included twice. This is a known issue when a file is included/required once in more than one place and the case of the line include is different in the two places e.g. require_once 'File.php'; and require_once 'file.php';.

    But, This one is being included twice by the same line in wp-includes/pluggable.php! Meaning it can’t possibly be that known issue because that line uses constants and a string literal to call the file which can not change between calls.

    maximinime

    (@maximinime)

    More info: It only affects the error class because it uses extends. See this answer on Stack Overflow.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp-cron.php – wp_mail not working’ is closed to new replies.