[英]Really basic help w/ a php contact form
I feel like I must be missing something simple here... Nothing sends, nor do I receive the success message. 我觉得这里一定缺少一些简单的东西……什么也没有发送,也没有收到成功消息。
<?php
if(isset($_POST['submit'])) {
$to = "michael@yahoo.com";
$subject = "Feedback Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
$emailSent = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Feedback Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<h1>Feedback Form</h1>
<?php if($emailSent == true) { //If email is sent ?>
<p><strong>Feedback Successfully Sent!</strong></p>
<?php } else {?>
<h3>Please submit your feedback</h3>
<?php } ?>
<form id="contactForm" action="index.php" method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" class="required" minlength="2"/>
<br/>
<label for="email">Email:</label>
<input type="text" name="email" id="email" class="required email"/>
<br/>
<label for="occupation">Occupation:</label>
<select name="occupation" id="occupation" class="required">
<option value="librarian">Librarian</option>
<option value="student">Student</option>
<option value="other">Other</option>
</select>
<br/>
<label for="message">Message:</label>
<textarea id="message" class="required" minlength="5"></textarea>
<br/>
<input class="submit" type="submit" value="Send" />
</form>
</div><!--end wrapper-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
</script>
<script type="text/javascript" src="/js/jquery.validate.pack.js"></script>
<script type="text/javascript" src="scripts.js"></script>
</body>
</html>
<input class="submit" type="submit" value="Send" />
Add name="submit"
to this for $_POST['submit']
to be set. 为此添加name="submit"
以设置$_POST['submit']
。
edit: $_POST['message']
may also not exist since it's name attribute is not set aswell. 编辑: $_POST['message']
也可能不存在,因为还没有设置其name属性。
Try with if (isset($_POST['name']))
in the first line. 尝试在第一行使用if (isset($_POST['name']))
。 $_POST['submit']
is not set. $_POST['submit']
未设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.