我是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" );
?>
答案 0 :(得分:1)
尝试设置
$email = "";
$author = "";
$visitor_email = "";
$comment = "";
在脚本的开头。
此外,我想知道即使没有提供信息,您是否打算发送电子邮件。如果是这种情况,那么
$comment = $_POST['comment'];
$comment = wordwrap($comment, 70);
应该移动到if ....如果你只想发送所有信息,那么你需要把所有其他信息移到if
答案 1 :(得分:0)
如何修复php文件的if条件..它可能有问题,尝试修复它: -
<?php
ini_set('display_errors',1);
if(isset($_POST['submit'])) {
// and add the name="submit" to the submit button
$email = $_POST['email'];
$author = $_POST['author'];
$visitor_email = $_POST['email'];
$comment = $_POST['comment'];
$comment = wordwrap($comment, 70);
}