2015-03-18 56 views
0

我想讓我簡單的聯繫表單工作。當它提交發送電子郵件時,它只顯示下一頁的代碼。所以我認爲它不是表單頁面,而是send_form_email.php。請幫我弄這個代碼工作,我不知道我在這裏錯過了什麼。我試過編輯代碼來工作,但它不會改變輸出。我把它放在pastebin中而不是在這裏,因爲我不能讓代碼格式正確。 http://pastebin.com/VFN7epGx代碼顯示,當我點擊提交我的電子郵件聯繫表格

if(
    !isset($_POST['first_name']) || 
    !isset($_POST['last_name']) || 
    !isset($_POST['email']) || 
    !isset($_POST['telephone']) || 
    !isset($_POST['comments']) 
) { 
    died('We are sorry, but there appears to be a problem with the form you submitted.');  

} 

$first_name = $_POST['first_name']; // required 
$last_name = $_POST['last_name']; // required 
$email_from = $_POST['email']; // required 
$telephone = $_POST['telephone']; // not required 
$comments = $_POST['comments']; // required 

//我認爲這可能與此

+0

你好如何解決? – javanoob17 2015-03-18 21:49:33

+0

我剛剛複製你的代碼並在本地主機上運行它。它適用於我的以下值:first_name = John last_name = Doe email = [email protected] telephone = 000111222333 comments =我是評論! – Marc 2015-03-18 21:50:50

+0

如果文件顯示爲純文本,則可能是php配置不正確。你確認了它的配置? – 2015-03-18 21:52:33

回答

0

添加一個else語句和使用的,而不是死回聲可能有助於做到: 如果(isset($ _ POST [ 'FIRST_NAME']) ||

!isset($_POST['last_name']) || 

!isset($_POST['email']) || 

!isset($_POST['telephone']) || 

!isset($_POST['comments'])) { 
echo('We are sorry, but there appears to be a problem with the form you submitted.'); 

} else { 



$first_name = $_POST['first_name']; // required 

$last_name = $_POST['last_name']; // required 

$email_from = $_POST['email']; // required 

$telephone = $_POST['telephone']; // not required 

$comments = $_POST['comments']; // required 
} 

對不起FPR壞的格式,我是我的手機上。明天我會看看這個在我的電腦上,如果你沒有解決它呢。

+0

嘿謝謝我仍然得到一串代碼來顯示 – javanoob17 2015-03-18 21:52:57

+0

它的奇怪它不斷顯示像這樣 – javanoob17 2015-03-19 19:16:09

0

我不能因爲它似乎已經被刪除了,但親自將它寫成這樣 - 並添加preg_replace()代碼來清理輸入。確保沒有任何東西意外關閉了php標籤,並且在腳本標籤之外沒有JavaScript掛起。

 if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { 
    echo 'We are sorry, but there appears to be a problem with the form you submitted.'; 
    }else{ 
    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 
    $comments = $_POST['comments']; // required 
    } 

我喜歡@ T.Somers做了什麼工作,以便清理 PHP Code losing its values when I hit submit

他的投入,這解釋了preg_replace相當不錯

Regular Expression clean method PHP通過@CodeCaster

相關問題