Ayaz Ali Shah
Ayaz Ali Shah

Reputation: 654

How to fix this ERROR 504 - GATEWAY TIMEOUT?

I am facing an error when i am trying to send email through php mailer. I have following code for sending email.

        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);

The above code is inside contact.php file and i am approaching it from form.php file through ajax. But it takes lot of time and at the end it is showing error.

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.

Can someone kindly let me know how to fix it?

Upvotes: 1

Views: 3411

Answers (2)

iDanielBH
iDanielBH

Reputation: 85

After several hours looking for the solution, I finally found that this parameter was necessary in my case:

$mail->SMTPAutoTLS = false

Upvotes: 0

Reuben Thompson
Reuben Thompson

Reputation: 350

I'd take a strong guess that the call to $mail->send() is timing out as the settings are wrong or you're being firewalled out. I'd suggest looking in the logs for your web server, most likely either /var/log/nginx/error_log or /var/log/php5/www.pool.log

Upvotes: 1

Related Questions