我为网站构建了一个PHP联系表单。服务器启用了邮件程序,代码将不会执行。我没有收到任何解析错误。有关dubugging的任何建议或问题是什么?
//Check the form submission
if (isset($POST['submitted'])){
//validate the form
if(!empty($_POST['name']) &&
!empty($_POST['email']) &&
!empty($_POST['comments']) ){
//Create the body
$body = "Name:
{$_POST['name']}\n\nComments:
{$_POST['comments']}";
//Make the Name no longer than 70 Characters
$body = wordwrap($body, 70);
//Send the email
mail('xxx@xxxx.com',
'Contact Form Submission',$body,
"From: {$_POST['email']}");
//Print the Thank You message
echo'<p>Thank you for contacting us we appreciate your interest</p>';
//Clear $_POST so that its not a sticky form
$_POST = array();
} else {
echo'<p>Please fill out the form completely.</p>';
}
}// End of main isset ()IF
表单代码是
<div id="wrapper">
<p>Please fill out this form to contact us.</p>
<form action="contact.php"method="post">
<p>Name: <input type="text" name="name"size="30"maxlength="60"value="<?php if(isset($_POST['name']))echo $_POST['name']; ?>" /></p>
<p>Email Address: <input type="text" name="email"size="30"maxlength="80"value="<?php if(isset($_POST['email']))echo $_POST['email']; ?>" /></p>
<p>Comments: <textarea name="comments"rows="5"cols="30"><?php if(isset($_POST['comments']))echo $_POST['comments']; ?></textarea></p>
<p><input type="submit" name="submit" value="Send" /> </p>
<input type="hidden" name="submitted" value="TRUE"/>
</form>
</div>
答案 0 :(得分:1)
我首先从额外的标题中删除花括号并添加\r\n
,如下所示:
if(mail('keith@kamtechnologyconsulting.com',
'Contact Form Submission',$body,
"From: ".$_POST['email']."\r\n")) {
echo "Thank you message";
} else {
//Maybe some appropriate logging and an errormessage here.
}
你可以选择更先进的东西,而是使用类似PHPMailer的东西。