我正在制作一份基本的“联系我们”表单,该表单将向用户发送一条快速消息。代码如下。当我测试它时,不会发送任何消息。但是,我可以使用sendmail
从命令行发送消息。
有人可以告诉我配置此设置需要做什么吗?我试过看PHP错误日志,但那里什么都没有。我可以在某处找到sendmail
日志吗?
此外,如果这有帮助,该网站将在AWS EC2实例上运行,其中DNS通过Route53配置,并由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>\n";
$headers.= "Content-Type:text/html; charset=UTF-8";
if($email_address != "") {
mail($to,$email_subject,$email_body,$headers);
return true;
}
}
?>