简体   繁体   中英

504 Gateway Time-out Error on PHP Mail / EC2

I'm trying to send an email using php's mail() function.

It worked fine in my local environment(macos). In EC2(ubuntu 16.0.6 LTS), mail is sent but a 504 error occurs.

504 Gateway Time-out
nginx/1.10.3 (Ubuntu)

I checked these things:

  • php.ini : smtp_port 25
  • open SMTP port 25 (inbound, outbound on VPC and sequrity group)

And my php code:

<?php

$message = $_POST['message'];

$to = "sample@example.com";
$charset = 'UTF-8';

$subject="subject example";

$message = "
<html>
    <head>
    <title>HTML email</title>
    </head>
    <body>
        <p><b>message</b></p>
        <p>$message</p>
    </body>
</html>
";

// headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <'sample@example.com'>' . "\r\n";

mail($to, $subject, $message, $headers);
?>

I put this php in the action of the form tag.

Has anyone ever experienced this problem?

You can increase maximum execution time in php.

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM