Title: wp-cron.php &#8211; wp_mail not working
Last modified: August 21, 2016

---

# wp-cron.php – wp_mail not working

 *  [Patrick Nießen](https://wordpress.org/support/users/hovida/)
 * (@hovida)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/)
 * 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: [http://pastebin.com/tA4JgEBC](http://pastebin.com/tA4JgEBC)
 * **Description:**
    For testing, i use the direct-link to wp-cron on my Browser(
   for example: [http://domain.com/wp-cron.php](http://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 Nießen](https://wordpress.org/support/users/hovida/)
 * (@hovida)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/#post-4093942)
 * SAME Problem is on **wp-login.php?action=lostpassword**
 *  [maximinime](https://wordpress.org/support/users/maximinime/)
 * (@maximinime)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/#post-4093973)
 * 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](https://wordpress.org/support/users/maximinime/)
 * (@maximinime)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/#post-4093976)
 * 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](https://wordpress.org/support/users/maximinime/)
 * (@maximinime)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/#post-4093977)
 * More info: It only affects the error class because it uses `extends`. See [this answer on Stack Overflow](http://stackoverflow.com/a/9669618/315024).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘wp-cron.php – wp_mail not working’ is closed to new replies.

## Tags

 * [cron](https://wordpress.org/support/topic-tag/cron/)
 * [php-error](https://wordpress.org/support/topic-tag/php-error/)
 * [wp core](https://wordpress.org/support/topic-tag/wp-core/)
 * [wp_mail](https://wordpress.org/support/topic-tag/wp_mail/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [maximinime](https://wordpress.org/support/users/maximinime/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/wp-cronphp-wp_mail-not-working/#post-4093977)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
