【问题标题】:Wordpress PHPmailer not workingWordPress PHPmailer 不工作
【发布时间】:2014-03-20 10:52:15
【问题描述】:

我正在尝试使用以下代码从 WordPress 插件发送电子邮件

include_once(ABSPATH . WPINC . '/class-phpmailer.php'); 
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->ContentType = 'text/plain'; 
            $mail->IsHTML(false);
            $mail->SetFrom(($enquiry_informations['display_email_address']!="")?$enquiry_informations['display_email_address']:"", "Autoquote");
            $mail->AddAddress($customer_email_address, $customer_email_name);
            $mail->Subject = $enquiry_informations['enquiry_autoresponse_subject'];
            $mail->Body = $autoresponse_msg;
            if($enquiry_informations['enquiry_autoresponse_attachment']!==NULL&&$enquiry_informations['enquiry_autoresponse_attachment']!==""){
                $mail->addAttachment(plugin_dir_path(__FILE__) . "attachments/" . $enquiry_informations['enquiry_autoresponse_attachment']);
            }
            $info = $mail->Send();
        if($info){
        echo "Sent";
}else{
    echo "Failed";
    echo $mail->ErrorInfo;
}

但是,我收到以下错误: 以下发件人地址失败:root@localhost:调用 Mail() 时未连接。 我做了一点谷歌搜索,发现这可能与协议有关。这是来自 wordpress 插件,所以我希望代码灵活(以便它可以在任何地方使用。所以不同的协议不会妨碍。)

【问题讨论】:

    标签: php wordpress phpmailer


    【解决方案1】:

    您在使用它时没有传递所有必要的值。当您使用isSMTP() 方法时,您还必须提供以下信息:

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'jswan';                            // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    

    阅读here如何正确使用类。

    【讨论】:

      【解决方案2】:

      我认为最好的办法是在 Wordpress 中使用邮件助手。

      http://codex.wordpress.org/Function_Reference/wp_mail

      错误可能是因为您缺少正确的 SMTP 配置,但我不知道也找不到如何调整 Wordpress 配置..

      希望对你有所帮助!

      【讨论】:

        猜你喜欢
        • 2014-03-14
        • 1970-01-01
        • 1970-01-01
        • 2012-05-21
        • 2014-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多