我有一个联系表单,但没有发送但是输出邮件已发送?任何人都可以看到问题吗?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail@email.co.uk";
//begin of HTML message
$message = "
From : $name,
Email: $email,
Subject: $subject,
Message: $message ";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Website Enquiry";
if (isset($_POST['name'])) {
// now lets send the email.
mail($to, $subject, $message, $headers);
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');
} else {
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');
}
?>
答案 0 :(得分:0)
尝试在From:in $ headers中输入电子邮件。
像$headers .= "From: youremail@provider.com"
或
$headers .= "From: Website Enquiry <youremail@provider.com>"
你应该把它改成
if(mail(...)) {
//success
}
else {
//email failed
}
答案 1 :(得分:0)
“From”标题应具有语法正确的电子邮件地址。您还需要检查“邮件”功能的返回值。
$header .= "From: Website Enquiry <enquiry@website.com>";
PS:请改进您的代码格式。