【问题标题】:Few chars getting replaced with '=' in mail content in wp_mailwp_mail 的邮件内容中很少有字符被“=”替换
【发布时间】:2016-03-14 13:34:17
【问题描述】:

每当从 wordpress 网站触发邮件时,邮件内容中的一些字母会随机替换为“=”。我已经在标题中设置了字符集和内容类型,即使这个奇怪的错误即将到来。有什么办法可以解决这个问题?

以下是我从 wordpress 网站触发邮件的代码:

$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);

我使用此代码收到的电子邮件如下:

尊敬的专家,

您的专业知识将有助于解决复杂的业务问题,从而帮助我们的员工更快地解决我们的客户问题。请求您在以下帖子中分享您的专业知识,该帖子已有 8 天没有得到回复。

帖子:RFP for Business De=elopment,Functional Testing,Technology Expert,Perfecto,Healthcare,Medical =anagement,Mobile,Digital,North America 这是动态内容,从数据库中检索

描述:客户要求 f=r RFQ 为 AHM 中的护理管理应用程序开发一个新的移动应用程序。 =HM 是 Aetna Inc. 的子公司。这是动态内容,从数据库中检索

点击这里回复帖子。

谢谢!

问候,ABC

注意:这是一封自动邮件。=请不要回复此邮件

完全不明白为什么随机字母会被 '=' 取代。请指出并提出问题所在

【问题讨论】:

  • 看起来它可能正在尝试以“引用的可打印”格式插入软换行符。有关类似问题,请参阅 stackoverflow.com/questions/15621510/…。可能是 wp_mail 默认为您未发送正确标头的格式或类似的格式。
  • (在我看来它可能是换行符的一个原因是它不是随机的——它每五十个字符添加=,这将是一个电子邮件中行长的不错选择!)
  • 这个问题很相似,但是在 wordpress 中解决这个问题的方法是什么

标签: php wordpress email


【解决方案1】:

按照 wordpress.org 上的以下链接中的建议评论几个返回语句并替换它们对我有用,现在邮件已正确发送并且等号“=”问题已解决。

通过在 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
    }

在此处阅读更多信息:https://core.trac.wordpress.org/ticket/33815

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-13
    • 2011-05-06
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多