Make WordPress Core

Ticket #4318: PN_mailfix.php

File PN_mailfix.php, 2.7 KB (added by morty, 18 years ago)

My Plugin for fixing the wp-mail problem

Line 
1<?php
2/*
3Plugin Name: Post Notification Mailfix
4Plugin URI: http://xn--strbe-mva.de/post-notification/
5Description: Fixes problems sending HTML-mails - Only for WP 2.2.x!
6Author: Moritz Str&uuml;be
7Version: 1.1.3
8License: GPL
9Author URI: http://xn--strbe-mva.de
10Min WP Version: 2.2
11
12*/
13
14
15if ( (!function_exists('wp_mail')) && class_exists('PHPMailer') ) :
16function wp_mail($to, $subject, $message, $headers = '') {
17        global $phpmailer;
18
19       
20        if ( !is_object( $phpmailer ) ) {
21                require_once(ABSPATH . WPINC . '/class-phpmailer.php');
22                require_once(ABSPATH . WPINC . '/class-smtp.php');
23                $phpmailer = new PHPMailer();
24        }
25
26        $mail = compact('to', 'subject', 'message', 'headers');
27        $mail = apply_filters('wp_mail', $mail);
28        extract($mail);
29
30        if ( $headers == '' ) {
31                $headers = "MIME-Version: 1.0\n" .
32                        "From: " . apply_filters('wp_mail_from', "wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']))) . "\n" . 
33                        "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
34        }
35
36        $phpmailer->ClearAddresses();
37        $phpmailer->ClearCCs();
38        $phpmailer->ClearBCCs();
39        $phpmailer->ClearReplyTos();
40        $phpmailer->ClearAllRecipients();
41        $phpmailer->ClearCustomHeaders();
42
43        $phpmailer->FromName = "WordPress";
44        $phpmailer->AddAddress("$to", "");
45        $phpmailer->Subject = $subject;
46        $phpmailer->Body    = $message;
47        $phpmailer->IsHTML(false);
48        $phpmailer->IsMail(); // set mailer to use php mail()
49
50        do_action_ref_array('phpmailer_init', array(&$phpmailer));
51
52        $mailheaders = (array) explode( "\n", $headers );
53        foreach ( $mailheaders as $line ) {
54                $header = explode( ":", $line );
55                switch ( trim( $header[0] ) ) {
56                        case 'From':
57                                $from = trim( str_replace( '"', '', $header[1] ) );
58                                if ( strpos( $from, '<' ) ) {
59                                        $phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) );
60                                        $from = trim( substr( $from, strpos( $from, '<' ) + 1 ) );
61                                        $from = str_replace( '>', '', $from );
62                                } else {
63                                        $phpmailer->FromName = $from;
64                                }
65                                $phpmailer->From = trim( $from );
66                                break;
67                        case 'Content-Type':
68                                $contentparam = explode(' ', trim($header[1]));
69                                $phpmailer->ContentType = substr(trim($contentparam[0]), 0, -1); //Remove ;
70                                if(!(strpos($contentparam[1], 'charset') === false)){
71                                        $charset = explode('=', $contentparam[1]);
72                                        $phpmailer->CharSet = str_replace( '"', '', $charset[1]);
73                                }
74                                break;
75                        default:
76                                if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' )
77                                        $phpmailer->AddCustomHeader( $line );
78                                break;
79                }
80        }
81
82        $result = @$phpmailer->Send();
83
84        return $result;
85}
86endif;
87
88
89
90?>