I am working on a basic Contact Us form that will send me a quick message from the user. The code is below. When I test it, no message is sent. However, I can send messages from command line using the sendmail
.
Could someone tell me what I need to do to configure this setup? I have tried looking at PHP error logs but there was nothing there. Can I find sendmail
logs somewhere?
Also, if this helps, the site is running on an AWS EC2 instance, with DNS configured through Route53 and is being served as a virtual host by the Apache.
<?php
if (isset($_POST) && sizeof($_POST) > 0) {
//$to = $_POST['to']['val']; // <=== Set static email here.
$to = "xxxx@test.com";
error_log("Entered the formdata.php script!", 0);
error_log("To value:" . $to, 0);
if (isset($_POST['formtype'])) {
unset($_POST['formtype']);
}
if (isset($_POST['to'])) {
unset($_POST['to']);
}
error_log("To value:" . $to, 0);
$email_address = $_POST['email']['val'];
error_log("Email address:" . $email_address, 0);
$email_subject = "Form submitted by: ".$_POST['name']['val'];
$email_body = "You have received a new message. <br/>".
"Here are the details: <br/><br/>";
foreach ($_POST as $key => $value) {
$email_body .= "<strong>" . $value['label'] . ": </strong> " . $value['val'] . "<br/><br/>";
}
$headers = "From:<$email_address>
";
$headers.= "Content-Type:text/html; charset=UTF-8";
if($email_address != "") {
mail($to,$email_subject,$email_body,$headers);
return true;
}
}
?>