【发布时间】:2019-07-31 17:56:27
【问题描述】:
我的联系表单有问题。电子邮件已正确发送,但在我的收件箱中显示为“发件人:anonymous@web.godns.net”而不是“发件人:web@mywebsite.com”,并直接进入垃圾邮件。
我一直在寻找类似的问题,但没有人给出具体的答案。我猜是代码有语法错误还是服务器问题。
这是 PHP 文件:
<?php
// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
http_response_code(500);
exit();
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = "myemail@gmail.com";
$subject = "Mensaje Web de >> $name";
$body = "Recibiste mensaje a través del formulario en la web.\n"."Estos son los datos:\n\nNombre y Apellido: $name\n\nEmail: $email\n\nTeléfono: $phone\n\nTexto del mensaje:\n$message";
$headers= "From: web@mywebsite.com" . "\r\n" .
"Reply-To: $email \r\n" .
'X-Mailer: PHP/' . phpversion();
if(!mail($to, $subject, $body, $headers))
http_response_code(500);
?>
有人知道这里出了什么问题吗? 谢谢,
亚历杭德拉 | aleare.design
【问题讨论】: