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