From 7f9f067e602b3d0e72ad1f067139cd955a5cbea0 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 28 Apr 2011 18:16:01 +0000 Subject: [PATCH] Use exceptions with phpmailer to avoid headers already sent errors. fixes #17228 git-svn-id: http://svn.automattic.com/wordpress/trunk@17753 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 9277db1a0..67a4df96c 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -281,7 +281,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() if ( !is_object( $phpmailer ) || !is_a( $phpmailer, 'PHPMailer' ) ) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; require_once ABSPATH . WPINC . '/class-smtp.php'; - $phpmailer = new PHPMailer(); + $phpmailer = new PHPMailer( true ); } // Headers @@ -400,7 +400,11 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() $to = explode( ',', $to ); foreach ( (array) $to as $recipient ) { - $phpmailer->AddAddress( trim( $recipient ) ); + try { + $phpmailer->AddAddress( trim( $recipient ) ); + } catch ( phpmailerException $e ) { + continue; + } } // Set mail's subject and body @@ -410,13 +414,21 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() // Add any CC and BCC recipients if ( !empty( $cc ) ) { foreach ( (array) $cc as $recipient ) { - $phpmailer->AddCc( trim($recipient) ); + try { + $phpmailer->AddCc( trim($recipient) ); + } catch ( phpmailerException $e ) { + continue; + } } } if ( !empty( $bcc ) ) { foreach ( (array) $bcc as $recipient) { - $phpmailer->AddBcc( trim($recipient) ); + try { + $phpmailer->AddBcc( trim($recipient) ); + } catch ( phpmailerException $e ) { + continue; + } } } @@ -455,16 +467,24 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() if ( !empty( $attachments ) ) { foreach ( $attachments as $attachment ) { - $phpmailer->AddAttachment($attachment); + try { + $phpmailer->AddAttachment($attachment); + } catch ( phpmailerException $e ) { + continue; + } } } do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); // Send! - $result = @$phpmailer->Send(); + try { + $phpmailer->Send(); + } catch ( phpmailerException $e ) { + return false; + } - return $result; + return true; } endif;