我无法通过我的网站联系表单回复邮件,因为当我在hostinger webmail上收到邮件时,'from'显示:u6078891 ... @ us-imm-web124.main-hosting.eu而不是发件人的电子邮件地址。我需要你的帮助
<?php
/* Set e-mail recipient */
$myemail = "info@mydomain.com";
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject = check_input($_POST['subject'], "Write a subject");
$email = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
$email = $full_name.'<'.$email.'>';
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$message = "Hello!
You have received a message from your website:
Name: $yourname
Subject: $subject
E-mail: $email
Message: $comments
End of message
";
$headers = 'From: ' .$email. "\r\n" .
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($myemail, $subject, $message);
header('Location: thanks.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
答案 0 :(得分:2)
您已定义了标题但未包含它们,因此mail()使用服务器设置。
mail($myemail, $subject, $message, $headers);