2012-12-17 120 views
0

我已經設置了一個簡單的聯繫表單,但在收尾過程中遇到了一些麻煩。每當提交表單時,我都會收到錯誤消息。希望有人可以看看我的代碼並指出我的錯誤。謝謝!聯繫表格提交錯誤

(編輯)忘了提及的錯誤是,一旦表單被提交,我被重定向到錯誤頁面(error.html),而不是成功(contactthanks.php)頁面。

HTML:

<form method="post" action="contactengine.php"> 
<label for="Name">Name:</label> 
<input type="text" name="Name" id="Name" /> 

<label for="City">City:</label> 
<input type="text" name="City" id="City" /> 

<label for="Email">Email:</label> 
<input type="text" name="Email" id="Email" /> 

<label for="Message">Message:</label><br /> 
<textarea name="Message" rows="20" cols="20" id="Message"></textarea> 

<input type="submit" name="submit" value="Submit" class="submit-button" /> 
</form> 

PHP:

<?php 

$EmailFrom = ""; 
$EmailTo = "[email protected]"; 
$Subject = ""; 
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 


$validationOK=true; 
if (!$validationOK) { 
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; 
exit; 
} 


$Body = ""; 
$Body .= "Name: "; 
$Body .= $Name; 
$Body .= "\n"; 
$Body .= "Tel: "; 
$Body .= $Tel; 
$Body .= "\n"; 
$Body .= "Email: "; 
$Body .= $Email; 
$Body .= "\n"; 
$Body .= "Message: "; 
$Body .= $Message; 
$Body .= "\n"; 


$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); 

if ($success){ 
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; 
} 
else{ 
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; 
} 
?> 
+3

...錯誤是? –

+0

你從這得到了什麼錯誤? – Gaurav

+0

我想你只是給變量和輸入類型命名。嘗試不同的名字。像$ name = Trim(stripslashes($ _ POST ['Name'])); smaill'name'而不是大寫'Name'。 希望它有幫助。 – Gaurav

回答

0

見什麼導致了問題

ini_set("display_errors", "1"); 
error_reporting(E_ALL);`. 

我的猜測是你有錯SMTP設置和mail功能失效。

1
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); 

if ($success){ 
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; 
} 
else{ 
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; 
} 

它重定向到您的錯誤頁面,因爲調用mail將返回false(表示電子郵件是不接受交付),而這正是你告訴它在這種情況下做的。

您需要檢查服務器上設置的SMTP。

通常,您的PHP.ini文件中要檢查的設置是sendmail_fromsendmail_path。鑑於您已經設置了From標題,sendmail_path很可能沒有正確設置。