#14710 closed feature request (wontfix)
PHPMailer class can cause an already declared error if including wp-config in an external script
Reported by: | teamplaylotto | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0.1 |
Component: | Keywords: | ||
Focuses: | Cc: |
Description
Can the next update please wrap PHPMailer class in a if(!class_exists('PHPMailer')){} block?
If I am using an external script and include wp-config.php so I can use wordpress functions outside of Wordpress and the external script has already included the PHPMailer class, trying to use any wordpress code that results in an email being sent will cause a fatal error due to the class already being declared.
This happens even if I wrap the external phpmailer class in the if not exists block because wordpress tries to declare the class after it has already been declared in the external script.
Change History (5)
#2
@
14 years ago
I suggest to close this ticket as wontfix. When WP is PHP 5.2 it can be more properly dealed with such issues by using spl_autoload_register() and doing wordpress class loading with it or something similar.
#3
in reply to:
↑ 1
@
14 years ago
- Resolution set to wontfix
- Status changed from new to closed
Replying to hakre:
wp_mail()
, the function which takes care of the include of/wp-includes/class-phpmailer.php
, is a so called plugable function.
You can replace it with your own implementation that takes care to not load phpmailer a second time.
Additionally and more easily than writing your own mail function, you can hook into
wp_mail
filter and execute$GLOBALS['phpmailer'] = new PHPMailer();
. That will prevent wordpress to include the file/wp-includes/class-phpmailer.php
.
big thanks, I did some digging in wp_mail of /wp-includes/pluggable.php
and was able to figure out what to do.
I set the ticket to 'wontfix'
wp_mail()
, the function which takes care of the include of/wp-includes/class-phpmailer.php
, is a so called plugable function.You can replace it with your own implementation that takes care to not load phpmailer a second time.
Additionally and more easily than writing your own mail function, you can hook into
wp_mail
filter and execute$GLOBALS['phpmailer'] = new PHPMailer();
. That will prevent wordpress to include the file/wp-includes/class-phpmailer.php
.