-1

我已经为一个站点建立了一个 PHP 联系表。服务器启用了邮件程序,代码将不会执行。我没有收到任何解析错误。关于调试的任何建议或问题是什么?

//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>  
4

1 回答 1

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之类的东西。

于 2013-01-30T15:37:26.947 回答