如何修复此ERROR 504 - GATEWAY TIMEOUT?

时间:2017-09-19 08:45:46

标签: php phpmailer

当我尝试通过php邮件发送电子邮件时,我遇到了错误。我有以下发送电子邮件的代码。

        require_once 'PHPMailer/PHPMailerAutoload.php';
        $response = array();
        //Create a new PHPMailer instance
        $mail = new PHPMailer;
        $mail->isSMTP();
        $mail->SMTPDebug = 0;
        $mail->Debugoutput = 'html';
        $mail->Host = "mail.example.com";
        $mail->Port = 25;
        $mail->SMTPAuth = true;
        $mail->Username = "*****@Example.com";
        $mail->Password = "*******";
        $mail->setFrom($to, $name);
        $mail->addAddress('*****', '***');
        $mail->Subject = $subject;
        $message =  '*******';
        $mail->msgHTML($message);
        $mail->AltBody = 'This is a plain-text message body';
        $mail->SMTPOptions = array(
            'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    ); 
    if (!$mail->send()){
        // For Debugging
        //return "Mailer Error: " . $mail->ErrorInfo;
        $response['error'] = 'Something not right. Please check your details.';
    }else{
        $response['success'] = 'Your email has been sent successfully.';
    }
    echo json_encode($response, JSON_PRETTY_PRINT);

上面的代码在contact.php文件中,我正在从form.php文件到ajax接近它。但这需要很多时间,最后却显示错误。

Why am I seeing this page?

The server that your request has reached is acting as a gateway or proxy to fulfil the request made by your client.

Web Browser => Web Front-End => Web Back-End

This server (Web Front-End) received an invalid response from an upstream (Web Back-End) server it accessed to fulfil the request.

In most cases this will not mean that the upstream server is down, but rather that the upstream server and the gateway/proxy do not agree on the protocol for exchanging data.

This problem is most commonly caused when there is a problem with IP communications between the Web Front and Back-Ends. Before you attempt to resolve this problem you should clear your browser cache completely.

Our support staff will be happy to assist you in resolving this issue. Please contact our Live Support or reply to any Tickets you may have received from our technicians for further assistance.

有人可以告诉我如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

我强烈猜测,对$ mail-> send()的调用是超时的,因为设置错误或者你被防火墙了。我建议你查看你的web服务器的日志,很可能是/ var / log / nginx / error_log或/var/log/php5/www.pool.log

答案 1 :(得分:0)

经过几个小时的寻找解决方案,我终于发现这个参数在我的情况下是必需的:

$mail->SMTPAutoTLS = false