我的网站上有一个带有php脚本的HTML网页表单。点击提交后,感谢页面加载,但提交的详细信息不会发送给收件人。
网站托管于1and1
http://www.evolutionroofingltd.co.uk/contact.html
谁能看到我做错了什么?
contact.php
<?php
/* Set e-mail recipient */
$myemail = "gregtwardochleb@hotmail.co.uk";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone'], "provide phone number");
$comments = check_input($_POST['comments'], "Write your comments");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
Name: $yourname
E-mail: $email
URL: $website
Comments:
$comments
End of message
";
/* Send the message using mail() function */
mail($myemail, $phone, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.htm');
exit();
/* Functions we used */
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 :(得分:0)
我很好奇使用$phone
作为主题 - 但除非有有趣的人物,否则我认为不是问题。
我建议在脚本的顶部打开错误报告(例如:error_reporting( E_ALL )
等),然后将if
条件附加到邮件功能,看看你得到了什么,即:
$res=mail( $myemail, $phone, $message );
if( !$res ) show_error( print_r( error_get_last (),1 ) );