Trying out phpmailer for wp_mail(). fixes #3862

git-svn-id: http://svn.automattic.com/wordpress/trunk@4946 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-02-25 20:23:25 +00:00
parent 2826681a18
commit 7effafd4ee
3 changed files with 2597 additions and 2 deletions

File diff suppressed because it is too large Load Diff

1045
wp-includes/class-smtp.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -156,13 +156,65 @@ endif;
if ( !function_exists('wp_mail') ) :
function wp_mail($to, $subject, $message, $headers = '') {
if( $headers == '' ) {
global $phpmailer;
error_log("mailing $subject\n", 0);
if ( !is_object( $phpmailer ) ) {
require_once(ABSPATH . WPINC . '/class-phpmailer.php');
require_once(ABSPATH . WPINC . '/class-smtp.php');
$phpmailer = new PHPMailer();
}
$mail = compact('to', 'subject', 'message', 'headers');
$mail = apply_filters('wp_mail', $mail);
extract($mail);
if ( $headers == '' ) {
$headers = "MIME-Version: 1.0\n" .
"From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" .
"Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
}
return @mail($to, $subject, $message, $headers);
$phpmailer->ClearAddresses();
$phpmailer->ClearCCs();
$phpmailer->ClearBCCs();
$phpmailer->ClearReplyTos();
$phpmailer->ClearAllRecipients();
$phpmailer->ClearCustomHeaders();
$phpmailer->FromName = "WordPress";
$phpmailer->AddAddress("$to", "");
$phpmailer->Subject = $subject;
$phpmailer->Body = $message;
$phpmailer->IsHTML(false);
$phpmailer->IsMail(); // set mailer to use php mail()
do_action_ref_array('phpmailer_init', array(&$phpmailer));
$mailheaders = (array) explode( "\n", $headers );
foreach ( $mailheaders as $line ) {
$header = explode( ":", $line );
switch ( trim( $header[0] ) ) {
case "From":
$from = trim( str_replace( '"', '', $header[1] ) );
if ( strpos( $from, '<' ) ) {
$phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) );
$from = trim( substr( $from, strpos( $from, '<' ) + 1 ) );
$from = str_replace( '>', '', $from );
} else {
$phpmailer->FromName = $from;
}
$phpmailer->From = trim( $from );
break;
default:
if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' )
$phpmailer->AddCustomHeader( $line );
break;
}
}
$result = @$phpmailer->Send();
error_log("mailing result $result\n", 0);
return $result;
}
endif;