我是 HTML 5 尤其是 PHP 的新手,我一直在尝试向我发送一封测试电子邮件,其中包含表单中的信息。我收到一封空白电子邮件,在检查 Apache 日志时,它显示来自 PHP 表单处理程序的未定义变量。
HTML 表单:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="formstyleb.css">
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script src="jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form action="formemail.php" method="post" enctype="text/plain" id="contact">
<fieldset>
<legend>Your Contact Details:</legend>
<div>
<label for="author">Name:(Required)</label>
<input name="author" class="required name" id="author" type="text"
title="Please Enter Your Name!">
</div>
<div>
<label for="email">Email Address:(Required)</label>
<input name="email"class="required email" id="email" type="text"
title="Please Enter a Valid email Address!">
</div>
<div>
<label for="comment">Comment:</label>
<textarea rows="12" id="message" name="comment"></textarea>
</div>
<div>
<button type="submit" id="submit" value="Submit as Multipart/form-data">
<img src="submit1.jpg" alt="Submit">
</button>
</div>
<div>
<button type="reset" id="reset">
<img src="resetrs.jpg" alt="reset">
</button>
</div>
</fieldset>
</form>
<script type="text/javascript" src="jqformval.js"></script>
</body>
</html>
PHP处理程序:
<?php
ini_set('display_errors',1);
/*stops undefined index error*/
if(isset($_POST['email'],$_POST['author'],$_POST['comment'] )) {
$email = $_POST['email'];
$author = $_POST['author'];
$visitor_email = $_POST['email'];
$comment = $_POST['comment'];
$comment = wordwrap($comment, 70);
}
$email_from = 'xxxx@yyyy.com';
$email_subject = "Form Submission";
$email_body = "Message from $author.\n".
"The message reads:\n $comment".
$to = "xxxx@yyyy.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$comment,$headers);
header( "Location: Thank You.html" );
?>