【问题标题】:phpMailer - localhost is currently unable to handle this request.phpMailer - localhost 当前无法处理此请求。
【发布时间】:2016-09-01 13:51:41
【问题描述】:

我的本​​地主机上有一个非常简单的 HTML CSS 和 javaScript 网站。我想做一个非常简单的联系表格。通常我通过插件使用 WordPress 来实现这一点,并且从未在普通网站中手动创建电子邮件。

我已经从https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php 下载了class.phpmailper.php 文件并将它放在我网站的根目录中。

在我的联系表格上我做了一个简单的

if(isset($_POST['submit'])){

}

并尝试发送电子邮件。我已经输入了我在 WordPress 网站上使用的相同 SMTP 详细信息,但是当我单击提交时,页面只会显示:

网站名称页面无法正常工作

envirofuel-redesign 目前无法处理此请求。

HTTP 错误 500

这是提交表单时执行的代码:

if(isset($_POST['submit'])){

    require_once('class.phpmailer.php');

    $subject = 'test';
    $body_of_your_email = 'hello test body';
    $mail = new PHPMailer();

    $mail->IsSMTP();                       // telling the class to use SMTP

    $mail->SMTPDebug = 0;
    // 0 = no output, 1 = errors and messages, 2 = messages only.

    $mail->SMTPAuth = true;                // enable SMTP authentication
    $mail->SMTPSecure = "";              // sets the prefix to the servier
    $mail->Host = "I PUT MY SMTP HOST HERE";        // sets Gmail as the SMTP server
    $mail->Port = 587;                     // set the SMTP port for the GMAIL

    $mail->Username = "I PUT MY USERNAME HERE";  // Gmail username
    $mail->Password = "I PUT MY PASSWORD HERE";      // Gmail password

    $mail->CharSet = 'windows-1250';
    $mail->SetFrom ('info@example.com', 'Example.com Information');
    $mail->AddBCC ( 'sales@example.com', 'Example.com Sales Dep.');
    $mail->Subject = $subject;
    $mail->ContentType = 'text/plain';
    $mail->IsHTML(false);

    $mail->Body = $body_of_your_email;
    // you may also use $mail->Body = file_get_contents('your_mail_template.html');

    $mail->AddAddress ('I PUT MY PERSONAL EMAIL HERE', 'Matthew');
    // you may also use this format $mail->AddAddress ($recipient);

    if(!$mail->Send())
    {
        $error_message = "Mailer Error: " . $mail->ErrorInfo;
    } else
    {
        $error_message = "Successfully sent!";
    }

}

有什么想法吗?

【问题讨论】:

  • ERROR 500 是服务器级错误。日志在说什么?你有任何调试工具在运行吗?
  • 您的代码基于一个过时的 PHPMailer 示例。更新它。您收到的错误(将在您的 Web 服务器日志中)可能是您尚未加载 SMTP 类。

标签: php phpmailer


【解决方案1】:

如果您的 Wordpress 网站能够发送电子邮件,那么您的电子邮件服务器设置应该没问题。

您可能需要配置您的 php 以使用 SMTP,请先尝试添加:

ini_set('SMTP','localhost' ); 
ini_set('sendmail_from', 'email_account_you_want@your_domain.com');

如果可行,那么您可以修改 php.ini 以使这些设置全局化。

[mail function]
SMTP = localhost
sendmail_from = email_account_you_want@your_domain.com

【讨论】:

    猜你喜欢
    • 2020-09-16
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 2017-03-06
    相关资源
    最近更新 更多