【问题标题】:PHPmailer - 500 internal server errorPHPmailer - 500 内部服务器错误
【发布时间】:2017-06-01 08:09:07
【问题描述】:

我使用 PHPmailer 在 GoDaddy 托管的网站上不断出现 500 内部服务器错误;我在 StackOverflow 上尝试了几种与我的挑战相关的解决方案,但都没有奏效。

这是我的代码:

require 'phpmailer/PHPMailerAutoload.php';
$feedback='';
$flag = array();
if(isset($_POST["submitlogin"]) and $_SERVER['REQUEST_METHOD'] == "POST"){

    $name = seo_friendly_url($_POST['name']);
    $email = seo_friendly_url($_POST['email']);
    $subject = seo_friendly_url($_POST['subject']);
    $message = seo_friendly_url($_POST['message']);

    //Email

    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
        $feedback="Invalid email format";
        array_push($flag,"false");
    }else {
        array_push($flag,"true");
    }
    //Email 

    //Name
    if (preg_match('/^[-a-zA-Z0-9._]+$/', $name)){  
        array_push($flag,"true");
    }else {
        $feedback="Invalid name format";
        array_push($flag,"false");
    }
    //Name


    if (!in_array("false", $flag)) {

        //SMTP needs accurate times, and the PHP time zone MUST be set
        //This should be done in your php.ini, but this is how to do it if you don't have access to that
        date_default_timezone_set('Etc/UTC');

        //Create a new PHPMailer instance
        $mail = new PHPMailer;
        //Tell PHPMailer to use SMTP
        $mail->isSMTP();
        //Enable SMTP debugging
        // 0 = off (for production use)
        // 1 = client messages
        // 2 = client and server messages
        $mail->SMTPDebug = 2;
        //Ask for HTML-friendly debug output
        $mail->Debugoutput = 'html';
        //Set the hostname of the mail server
        $mail->Host = "smtpout.asia.secureserver.net";
        //Set the SMTP port number - likely to be 25, 465 or 587
        $mail->Port = 25;
        //Whether to use SMTP authentication
        //$mail->Username = 'email@email.com'; 
        //$mail->Password = 'password'; 
        $mail->SMTPAuth = false;
        //Set who the message is to be sent from
        $mail->setFrom('email@email.com');
        //Set an alternative reply-to address
        $mail->addReplyTo($email);
        //Set who the message is to be sent to
        $mail->addAddress('email@email.com');     // Add a recipient
        $mail->addAddress('email@email.com');
        $mail->addAddress('email@email.com);
        //Set the subject line
        $mail->Subject = 'HLS Inquiry';
        //Read an HTML message body from an external file, convert referenced images to embedded,
        //convert HTML into a basic plain-text alternative body
        $mail->msgHTML($message);







        $email_ar = $email;
        $subject_ar = $name.", Thank you for your Inquiry"; 
        $acknowledgement_receipt = '
            <div style="padding:10px 20px;font-size:16px;">

                <p>Dear '.$name.',</p>

                <p>We&#39;ve received your message and would like to thank you for contacting us. We will reply by email shortly.</p>

                <p>Talk to you soon,</p>

                <p>
                    <div>Customer Service</div>

                </p>

            </div>
        ';



        if ($mail->send()) {
            $feedback = "<span style='color:green;'>Thank you for your inquiry. We will respond to you within 24 hours.</span>";
        } 

}

请注意,为了我的隐私,我将一些电子邮件值替换为:email@email.com

我认为电子邮件设置是正确的,因为我已经使用了 JustHost 托管的朋友网站上的这些设置。

【问题讨论】:

  • 尝试用双引号替换 addAddress('email@email.com') -> addAddress("email@email.com")

标签: php phpmailer


【解决方案1】:

有一个“拆分”函数用于编写 PHPMailer 类。此函数已被弃用很久,因此在以后的 PHP 版本中会出错。 找到它们并替换为“explode”。 这对我有用。

【讨论】:

    【解决方案2】:

    此行缺少单引号:

    $mail->addAddress('email@email.com);
    

    这在 SO 中非常明显,因为您可以看到语法高亮显示在这一点上是如何中断的。

    当您收到错误 500 并且没有显示任何内容时,这表明您应该查看 Web 服务器的错误日志。

    【讨论】:

    • 我尝试输入缺少的单引号,但还是不行 :( 我在哪里可以看到服务器日志?
    • 通常在/var/log/apache2/error.log 或类似的地方。
    猜你喜欢
    • 1970-01-01
    • 2019-01-17
    • 2011-10-17
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多