我需要帮助我的错误编码的php联系表单
HTML CODE:
<div id="contact_form" >
<form method="post" name="contact" action="contact.php">
<label for="author" style="font-size:14px;">Your Full Name:</label>
<input type="text" id="author" name="name" class="input_field" />
<div class="clear h20"></div>
<label for="email" style="font-size:14px;">Your Phone Number/Email:</label
<input type="text" id="email" name="email" class="input_field" />
<div class="clear h20"></div>
<label for="text" style="font-size:14px;">Message:</label>
<textarea id="text" name="comment" rows="0" cols="0" class="required"></textarea>
<div class="clear h20"></div>
<input style="font-size:16px;" type="submit" name="submit" value="Send" />
</form>
</div>
以下是加载的代码,形成CONTACT.PHP到HTML PHP代码:(contact.php)
<?php
if(isset($_POST['submit'])) {
$to = "xxx@gmail.com";
$subject = "Contact Us";
// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";
// ...and away we go!
mail($to, $subject, $body);
?>
答案 0 :(得分:0)
<?php
if(isset($_POST['submit'])) {
$to = "xxx@gmail.com";
$subject = "Contact Us";
// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";
// ...and away we go!
mail($to, $subject, $body);
}
?>
答案 1 :(得分:0)
您忘了在代码末尾关闭{。
<?php
if(isset($_POST['submit'])) {
$to = "xxx@gmail.com";
$subject = "Contact Us";
// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From:" .$name_field."\n\n E-Mail: ".$email_field."\n\n Message:\n\n ".$comment";
// ...and away we go!
mail($to, $subject, $body);
}
?>