2010-06-21 21 views
0

好了,所以我做了使用HTML表單,我想獲得它的信息提交給我的電子郵件,讓我發現和修改這個PHP腳本:爲什麼我的HTML/PHP表單不工作?

<?php 
$to = "[email protected]"; 
$subject = "R&R Form"; 
$firstname1 = $_REQUEST['firstname1'] ; 
$lastname1 = $_REQUEST['lastname1'] ; 
$firstname2 = $_REQUEST['firstname2'] ; 
$lastname2 = $_REQUEST['lastname2'] ; 
$department1 = $_REQUEST['department1'] ; 
$department2 = $_REQUEST['department2'] ; 
$reason = $_REQUEST['reason'] ; 
$behaviour1 = $_REQUEST['behaviour1'] ; 
$behaviour2 = $_REQUEST['behaviour2'] ; 
$behaviour3 = $_REQUEST['behaviour3'] ; 
$behaviour4 = $_REQUEST['behaviour4'] ; 
$behaviour5 = $_REQUEST['behaviour5'] ; 
$behaviour6 = $_REQUEST['behaviour6'] ; 
$behaviour7 = $_REQUEST['behaviour7'] ; 

$message = "Nominee: $firstname1 $lastname1 /n Department: $department1 /n /n Nominator: $firstname2 $lastname2 /n Department: $department2 /n /n Reason for nomination: $reason /n /n Additional reasons: $behaviour1 /n $behaviour2 /n $behaviour3 /n $behaviour4 /n $behaviour5 /n $behaviour6 /n $behaviour7 /n"; 

$headers = "Recognition and Reward Request for $firstname1 $lastname1"; 
$sent = mail($to, $subject, $message, $headers,) ; 
if($sent) 
{print "Your nomination was submitted successfully"; } 
else 
{print "We encountered an error submitting your nomination"; } 
?> 

這不是寫得很好,我知道(我今天才開始學習PHP,而且我只是修改了我複製並粘貼的腳本),但它似乎沒有任何語法錯誤或任何其他我能看到的錯誤。我並不是要求某人爲我修復我的代碼,我只是要求提供一些指示,說明腳本爲什麼不能像應該那樣工作。

我把它上傳到安裝了PHP的服務器,所以這不是問題。我一直試圖弄清楚這一點,而且這有點令人沮喪。有人請幫忙?

+0

這是什麼錯誤? – 2010-06-21 20:35:26

回答

0

既然您是初學者,我建議您儘可能多地使用PEAR。

看看:pear html quickform

它會真的讓你的生活更輕鬆。

以及發送電子郵件,我建議你使用:PHPMailer的

它配備了大量的電子郵件功能恰到好處外的開箱

2

那麼,該腳本使用本作的標題,這是無效的:

$headers = "Recognition and Reward Request for $firstname1 $lastname1"; 

也許你的意思爲是主題行?

的標題應該是有效的SMTP頭,是這樣的:

$headers = 'From: [email protected]' . "\r\n"; 

看爲mail function的例子以獲得更多信息。

+0

+1因爲我同意 – DRL 2010-06-21 20:40:49

2
$sent = mail($to, $subject, $message, $headers,) ; 

應該是這樣的:

$sent = mail($to, $subject, $message, $headers) ; 

(沒有逗號)

希望我幫助

0

它確實有語法錯誤。由於您看不到它們,我建議您啓用完整的錯誤報告。有很多方法可以做到這一點;最簡單的可能是將腳本添加到您的腳本之上:

<?php 

ini_set('display_errors', true); 
error_reporting(E_ALL); 

?> 
+0

哇,謝謝你的迴應! – Ismail 2010-06-22 11:17:32