1

Whenever mails are triggered from a 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 a 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('[email protected]',$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

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.