【问题标题】:500 Internal Server error with SMTP on wordpress custom templatewordpress 自定义模板上的 SMTP 出现 500 内部服务器错误
【发布时间】:2021-07-11 11:14:41
【问题描述】:

我正在使用 SMTP 发送电子邮件。为此,我使用了 WP Mail SMTP 插件 (https://wordpress.org/plugins/wp-mail-smtp/) 我使用 WP Mail SMTP 插件测试了邮件并且它可以工作。现在我想用我在 WordPress 模板中创建的 SMTP 功能发送邮件

这是我的模板文件代码

<?PHP 
/* Template Name: smt */
get_header(); 

        require '/PHPMailer/class.PHPMailer.php';
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->Host = "******";
        $mail->Username = "******";
        $mail->Password = "***********";
        $mail->SMTPAuth   = true;
        $mail->SMTPSecure = "tls";
        $mail->Port       = 587;
        $mail->From = "no-reply@*****.com";
        $mail->FromName = "zaata";
        $mail->AddAddress('anaiycvktquiech@gmail.com');
        $mail->IsHTML(true);
        $mail->Subject = "zaata Varification code";
        $mail->Body    = "testmail";
        $mail->IsHTML(true);                      
        if(!$mail->Send())
        {
            echo 'false';
        }
            echo 'send';
    }

 ?>

它在控制台中显示 itsugestion.com/:1 GET *******.com/dev/smt/ 500 (Internal Server Error)

请帮助我如何在 WordPress 模板中设置 SMTP 任何帮助表示赞赏。

【问题讨论】:

  • 查看debug log 以获取有关 500 内部服务器错误的更多详细信息并报告您的发现。
  • 安装 wp-mail-smtp 后,您可以使用插件描述中的wp_mail 功能WP Mail SMTP plugin easily resolves email delivery problems by improving and changing how your WordPress site sends email. We reconfigure the wp_mail() function to either use proper SMTP host credentials or leverage a built-in SMTP mail provider.

标签: php wordpress email smtp custom-wordpress-pages


【解决方案1】:

正如我在对您的问题的评论中提到的,最好只使用wp_mail(),因为插件使其使用 smtp,至于错误 500,您缺少 if 语句的 else 部分

<?PHP 
/* Template Name: smt */
get_header(); 

        require '/PHPMailer/class.PHPMailer.php';
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->Host = "******";
        $mail->Username = "******";
        $mail->Password = "***********";
        $mail->SMTPAuth   = true;
        $mail->SMTPSecure = "tls";
        $mail->Port       = 587;
        $mail->From = "no-reply@*****.com";
        $mail->FromName = "zaata";
        $mail->AddAddress('anaiycvktquiech@gmail.com');
        $mail->IsHTML(true);
        $mail->Subject = "zaata Varification code";
        $mail->Body    = "testmail";
        $mail->IsHTML(true);                      
        if(!$mail->Send())
        {
            echo 'false';
        } else {
            echo 'send';
        }
 ?>

【讨论】:

    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 2011-05-05
    • 1970-01-01
    相关资源
    最近更新 更多