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" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";
$headers .= 'From: <'sample@example.com'>' . "
";
mail($to, $subject, $message, $headers);
?>
I put this php in the action of the form tag.
Has anyone ever experienced this problem?