PHP联系表格问题
|
我在使用简单的PHP联系人表单时遇到问题。发送表单时,我没有遇到任何错误,但是没有任何内容发送到我的电子邮件中。
任何帮助,将不胜感激。
这是HTML
<form method=\"POST\" name=\"contactform\" action=\"contact-form-handler.php\">
<p>
<label for=\'name\'>Your Name:</label> <br>
<input type=\"text\" name=\"name\">
</p>
<p>
<label for=\'email\'>Email Address:</label> <br>
<input type=\"text\" name=\"email\"> <br>
</p>
<p>
<label for=\'message\'>Message:</label> <br>
<textarea name=\"message\"></textarea>
</p>
<input type=\"submit\" value=\"Submit\"><br>
</form>
和PHP
<?php
$errors = \'\';
$myemail = \'name@website.com\';//<-----Put Your email address here.
if(empty($_POST[\'name\']) ||
empty($_POST[\'email\']) ||
empty($_POST[\'message\']))
{
$errors .= \"\\n Error: all fields are required\";
}
$name = $_POST[\'name\'];
$email_address = $_POST[\'email\'];
$message = $_POST[\'message\'];
if (!preg_match(
\"/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i\",
$email_address))
{
$errors .= \"\\n Error: Invalid email address\";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = \"Contact form submission: $name\";
$email_body = \"You have received a new message. \".
\" Here are the details:\\n Name: $name \\n Email: $email_address \\n Message \\n $message\";
$headers = \"From: $myemail\\n\";
$headers .= \"Reply-To: $email_address\";
mail($to,$email_subject,$email_body,$headers);
//redirect to the \'thank you\' page
header(\'Location: contact-form-thank-you.html\');
}
?>
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
没有找到相关结果
已邀请:
4 个回复
芳菱挨啡
调用后放置
,以在重定向后不发送其他HTML。
舶啥戚
原始答案版本-
蹄寄噬非芹
电话,那么您的所有输入都很好。注意
返回一个布尔值也很有用,因此您可以执行以下操作:
如果看到该错误,则表示php.ini中没有正确配置ѭ7。有关您需要在php.ini中设置的值的更多信息,请参见此文章:http://www.techrepublic.com/article/a-tour-of-the-phpini-configuration-file-part-2/5272345
净爽
这可能会有所帮助。