2013-10-21 56 views
0

嘿所有我改變腳本閱讀這樣現在,但現在當我點擊去按鈕,它只是顯示一個空白的白色屏幕HTML正在推動按鈕正在工作:PHP腳本有錯誤,但沒有顯示

<?php 

    if(isset($_POST['email'])) { 

// EDIT THE 2 LINES BELOW AS REQUIRED 
$email_to = "[email protected]"; 
$email_subject = "Sva Sva Spa Salon Coming Soon Notify Email"; 


function died($error) { 
    // your error code can go here 
    echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
    echo "These errors appear below.<br /><br />"; 
    echo $error."<br /><br />"; 
    echo "Please go back and fix these errors.<br /><br />"; 
    die(); 
} 

// validation expected data exists 
if (!isset($_POST['email']) 
    died('We are sorry, but there appears to be a problem with the form you submitted.'));  


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

$error_message = ""; 
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 

$email_message = "Form details below.\n\n"; 

function clean_string($string) { 
    $bad = array("content-type","bcc:","to:","cc:","href"); 
    return str_replace($bad,"",$string); 
} 

$email_message .= "Email: ".clean_string($email_from)."\n"; 


    // create email headers 
    $headers = 'From: '.$email_from."\r\n"; 
    'Reply-To: '.$email_from."\r\n" ; 
    'X-Mailer: PHP/' . phpversion(); 
    $mail($email_to, $email_subject, $email_message, $headers); 

} 
?> 

    !-- include your own success html here --> 

Thank you for contacting us. We will be in touch with you soon to let you know when  
the new website will be up and running. 
To go back to the home page click <a href="http://www.svaspasalon.com">Here</a> 

<?php 
    ?> 

MY FORM HTML: 
    <form name="contactform" method="post" action="contact.php"> 
      <input type="text" name="email" placeholder="Provide  
    EMAIL for Reminder" maxlength="80" size="30"> 
      <input type="submit" class="go" value="">  
     </form> 

感謝您的幫助!

+0

什麼? –

+0

嘗試'var_dump'ing'$ _POST ['email']'。這可能是您的HTML表單的問題。 (我喜歡隨機把名詞變成動詞)。 –

+0

@ Superscript我在這裏添加了我的表單html鏈接:

\t \t \t \t \t \t \t \t \t \t \t \t \t
user2895617

回答

5

您從未定義過$mail,所以你的最後if()測試是完全沒有意義的。

$mail = mail(...); 
^^^^^^^--- need this 

if ($mail) { ... } else { ... } 

一般提示:NEVER使用@錯誤抑制運營商,尤其是當你遇到麻煩。這就是將你的手指伸入耳朵的編碼等同於「lalalalala聽不到你lalalalalalal」。

+3

+1中,只是爲了評論'@'! – 2013-10-21 20:50:25

1

你如果語句包含一個錯誤||所以if試圖評估呼叫died爲真或假(意思是died總是獲取運行)

變化:

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

if (!isset($_POST['email']) 
    died('We are sorry, but there appears to be a problem with the form you submitted.'); 
+0

它除非設置$ _POST ['email']',否則它永遠不會進入代碼的那一部分:所以出現比這更多的錯誤。 –

+0

如果未設置'$ _POST ['email']',它將不會打印任何內容,因爲所有代碼都被封裝在一個if block – immulatin

0

拳頭:郵件功能只工作smtp服務器安裝機器。可能是你跳過它。

第二:你確實使用@mail。 @符號鈍化郵件功能錯誤。

0

要查看錯誤,把這個頂部(將代碼在生產之前將其刪除!):

有關配置Apache以顯示錯誤
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
+0

@ Jeroen我試過了,什麼都沒有發生? – user2895617

相關問題