php 500:使用 PHPMailer 时出现内部服务器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16684396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:32:38  来源:igfitidea点击:

500: Internal Server Error in using PHPMailer

phperror-handlingphpmailerinternal-server-error

提问by Kerry

I'm trying to send an email using the following code and I'm getting Internal Server Error. I am not sure why I am having this trouble.

我正在尝试使用以下代码发送电子邮件,但出现内部服务器错误。我不知道为什么我会遇到这个问题。

PHP code:

PHP代码:

<?php
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = '[email protected]';  
    $mail->Password = "mypasswordhere";           
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress('[email protected]');
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
?>

I just placed this file as test.php inside the PhpMail folder after extracting it. Like the below

解压后,我将此文件作为 test.php 放置在 PhpMail 文件夹中。像下面这样

enter image description here

在此处输入图片说明

采纳答案by Raptor

You missed a single quote on the line:

您错过了一行中的单引号:

$mail->Password = 'mypasswordhere';     

The error behind is probably a PHP parsing error, which is shown in your Apache error log.

后面的错误很可能是 PHP 解析错误,它显示在您的 Apache 错误日志中。