0

Whenever mails are triggered from wordpress site, a few alphabets are randomly getting replaced with '=' in the mail content. I have set the charset and content type in headers even then this weird error is coming. What could be the possible fix to this ?

Below is my code to trigger mails from wordpress site:

$footerText = "<br/><br/>
                               Regards,<br/>
                               ABC<br/><br/>
                               Note: This is an automated mail. Please do not reply to this message";
$post = get_post($postId); 
                        $post_date = strtotime($post->post_date);
                        $author_email = get_the_author_meta( 'user_email', $post->post_author);
                        $headers = array();
                        $headers[] = 'Content-type: text/html; charset=UTF-8';
                        $headers[] = 'From: '.FROM_EMAIL;
                        //$headers[] = 'Bcc: '.$author_email;
                        $subject = "Request to share your expertise on - '".$post->post_title."'";  
                        $post_title = $post->post_title;
                        $post_content = $post->post_content;
                        $post_url = get_permalink($post->ID);
                        $mail_message = "Your expertise would help solve complex business problems that would 
                                        help our associates solve our client problems faster.
                                        Request you to share your expertise on the following post, 
                                        which has not been answered for over ".$days." days now.<br/><br/>
                                        Post: <strong>".$post_title."</strong><br/>
                                        Description: ".$post_content."<br/><br/>
                                        Click <a href='".$post_url."'>here</a> to respond to the post.<br/><br/>
                                        Thanks You!
                                        ".$footerText;
$hello_text = "Dear Expert,<br /><br />";
                                        $full_message = $hello_text.$mail_message;
                                        wp_mail('abc@gmail.com',$subject,$full_message,$headers);

Emails that i receive using this code is as follows:

Dear Expert,

Your expertise would help solve complex business p=oblems that would help our associates solve our Cli=nt(s) problems faster. Request you to share your experti=e on the following post, which has not been answered for o=er 8 days now.

Post: RFP for Business De=elopment,Functional Testing,Technology Expert,Perfecto,Healthcare,Medical =anagement,Mobile,Digital,North America This is Dynamic content, retrieved from database

Description: Customer is asking f=r RFQ to develop a new mobile app for care management application in AHM. =HM is a subsidary of Aetna Inc. This is Dynamic content, retrieved from database

Click here to respond to the post.

Thank you!

Regards, ABC

Note: This is an automated mail.=lease do not reply to this message

Totally confused on why random letters are getting replaced with '='.Kindly point out and suggest what is wrong with this

immazharkhan
  • 395
  • 2
  • 12
  • 1
    Looks like it might be trying to insert a soft line break in "quoted printable" format. See http://stackoverflow.com/questions/15621510/how-to-understand-the-equal-sign-symbol-in-imap-email-text for a similar question. It may be that `wp_mail` defaults to a format for which you're not sending the correct header, or something like that. – Matt Gibson Dec 09 '15 at 10:23
  • 1
    (One reason it looks like it might be a line break to me is that it's *not* random--it's adding the `=` every fifty characters, which would be a decent choice for line length in an email!) – Matt Gibson Dec 09 '15 at 10:29
  • That issue is similar, but what would be the fix for the same in wordpress – immazharkhan Dec 09 '15 at 10:59

1 Answers1

1

Commenting couple of return statements and replacing them as suggested in the below link on wordpress.org worked for me, now the mails are sent properly and the equal sign '=' issue is solved.

Fixed by making following changes in wp-includes\class-phpmailer.php

public function encodeQP($string, $line_max = 76)
    {
        // Use native function if it's available (>= PHP5.3)
        if (function_exists('quoted_printable_encode')) {
            //return $this->fixEOL(quoted_printable_encode($string)); commented this one
            return quoted_printable_encode($string); // added this line
        }
        // Fall back to a pure PHP implementation
        $string = str_replace(
            array('%20', '%0D%0A.', '%0D%0A', '%'),
            array(' ', "\r\n=2E", "\r\n", '='),
            rawurlencode($string)
        );
        $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
        //return $this->fixEOL($string); commented this one
        return $string; // added this line
    }

Read more here: https://core.trac.wordpress.org/ticket/33815

immazharkhan
  • 395
  • 2
  • 12