Html PHP web表单未发送电子邮件


Html PHP web form not sending email?

我用php脚本创建了一个html表单,以便在用户点击"发送"时ping电子邮件。然而,当点击"发送"时,我收到了一个错误"请更正以下错误:"有人能告诉我我是否正确连接了表单,或者我的php脚本是否错误吗。谢谢

contact.htm

<html>
<body>
<p>Required fields are <b>bold</b></p>
<form action="contact.php" method="post">
<p><b>Your Name:</b> <input type="text" name="yourname" /><br />
<b>Subject:</b> <input type="text" name="subject" /><br />
<b>E-mail:</b> <input type="text" name="email" /><br />
Website: <input type="text" name="website"></p>
<p>Do you like this website?
<input type="radio" name="likeit" value="Yes" checked="checked" /> Yes
<input type="radio" name="likeit" value="No" /> No
<input type="radio" name="likeit" value="Not sure" /> Not sure</p>
<p>How did you find us?
<select name="how">
<option value=""> -- Please select -- </option>
<option>Google</option>
<option>Yahoo</option>
<option>Link from a website</option>
<option>Word of mouth</option>
<option>Other</option>
</select>
<p><b>Your comments:</b><br />
<textarea name="comments" rows="10" cols="40"></textarea></p>
<p><input type="submit" value="Send it!"></p>
<p> </p>
</form>
</body>
</html>

谢谢.htm

<html>
<body>
<p><b>Your message was sent</b></p>
<p>Your message was successfully sent!
Thank you for contacting us, we will reply
to your inquiry as soon as possible!</p>
</body>
</html>

contact.php

<?php
$myemail  = "gregtwardochleb@hotmail.co.uk";
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject  = check_input($_POST['subject'], "Write a subject");
$email    = check_input($_POST['email']);
$website  = check_input($_POST['website']);
$likeit   = check_input($_POST['likeit']);
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");
if (!preg_match("/(['w'-]+'@['w'-]+'.['w'-]+)/", $email))
{
show_error("E-mail address not valid");
}
if (!preg_match("/^(https?:'/'/+['w'-]+'.['w'-]+)/i", $website))
{
$website = '';
}
$message = "Hello!
Your contact form has been submitted by:
Name: $yourname
E-mail: $email
URL: $website
Like the website? $likeit
How did he/she find it? $how_find
Comments:
$comments
End of message
";
mail($myemail, $subject, $message);
header('Location: thanks.htm');
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();
}
?>

您的HTML页面被重定向到联系人页面。在"联系页面"中,您已经写下了指示的代码

<b>Please correct the following error:</b><br />

您的代码中有以下项目吗?

$website  = check_input($_POST['website']);
$likeit   = check_input($_POST['likeit']);
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");

请告诉我你到底想做什么。

您缺少一些输入,因为您已经包含在contact.php之类的网站中,如何,喜欢您没有从表单输入中发布的内容

<html>
<body>
 <form action="contact.php" method="post">
  <p><b>Your Name:</b> <input type="text" name="yourname" /><br />
  <b>Subject:</b> <input type="text" name="subject" /><br />
  <b>E-mail:</b> <input type="text" name="email" /><br />
  <b>Website:</b> <input type="text" name="website" /><br />
  <b>Like the website:</b> <input type="text" name="likeit" /><br />
  <b>How did he/she find it:</b> <input type="text" name="how" /><br />
  <p><b>Your comments:</b><br />
  <textarea name="comments" rows="10" cols="40"></textarea></p>
  <p><input type="submit" value="Send it!"></p>
 </form>
</body>
</html>

php邮件功能不会在本地主机上工作,因为它需要域信息来发送邮件。所以你们必须先把它放到服务器上。希望它能为你工作