2015-09-18 240 views
1

我需要幫助其被錯誤編碼我的PHP的聯繫表格PHP發送不工作電子郵件

HTML代碼:

<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 = "[email protected]"; 
$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

您使用的是wamp還是Xamp?如果是的話,它是在線還是離線。你在哪裏發帖? –

+0

PLZ任何人都可以在代碼中找到錯誤,因爲我不想更換整個編碼... plz guys – ThomasWeb

+0

它在服務器上在線 – ThomasWeb

回答

0

你就不能關閉支架! 有效的代碼是:

<?php 
if(isset($_POST['submit'])) { 
    $to = "[email protected]"; 
    $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

也許可以解釋他在做什麼這會有幫助嗎? – Crecket

+0

我did not understand ...我仍然是一個小白菜編程和你的幫助,我可以提高自己 – ThomasWeb

+0

@ user2135539它說: 解析錯誤:語法錯誤,意想不到'''在12行/contact.php – ThomasWeb

0

您忘記關閉您的{在代碼結束時。

<?php 
if(isset($_POST['submit'])) { 
$to = "[email protected]"; 
$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); 
} 
?>