2013-05-02 138 views
0

嘿,我不能爲我的生活弄清楚我在哪裏出錯了。表單提交時將其帶到空白頁面。沒有錯誤或確認。只是空白。我假設這是一個語法錯誤,但我不能看到它出於某種原因。你們看到什麼了嗎? 這裏是我的表單代碼:php mail()腳本不工作

<form method="POST" action="mailtest.php"> 

<label>Name<span class="req">*</span></label> 
<input name="name" placeholder="Type Here"> 

<label>Email<span class="req">*</span></label> 
<input name="email" type="email" placeholder="Type Here"> 

<label>Subject</label> 
<input name="subjectf" placeholder="Type Here"> 

<label>Message<span class="req">*</span></label> 
<textarea name="message" placeholder="Type Here"></textarea> 

<input class="submit" name="submit" type="submit" value=""> 
<span class="right" style="color:red">* represents a mandatory field.</span> 
</form> 

,這裏是PHP腳本我有mailtest.php頁:

<?php 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $from = $_POST['name']; 
    $to = '[email protected]'; 
    $subject= 'new enquiry on website'; 
    $subjectf= $_POST['subjectf']; 
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message"; 

    if ($_POST['submit']) { 
    if ($name != '' && $email != '' && $message != '') {   
      if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>'; 
     } else { 
      echo '<p>Something went wrong, go back and try again!</p>'; 
     } 
    } else { 
     echo '<p>You need to fill in all required fields!!</p>'; 
    } 
} 
?> 
+0

isset($ _ POST [ '提交']) 可能會幫助:) – 2013-05-02 02:28:39

+0

郵件是一個棘手的事情來調試,你是否收到任何錯誤信息? – 2013-05-02 02:28:45

+0

根本沒有錯誤信息。只是一個空白頁面。我剛剛嘗試了「isset($ _ POST ['submit'])」,它給了我這個錯誤「解析錯誤:語法錯誤,意想不到'{'在11行中的/home/a2375440/public_html/mailtest.php錯誤:語法錯誤,意想不到''在第11行的/home/a2375440/public_html/mailtest.php中。第11行是我剛剛插入的那行 – user2291730 2013-05-02 02:32:16

回答

1

您應該首先檢查表格是否已提交

刪除if ($_POST['submit'])並且把它放在腳本的頂部..

還應該檢查whther的$_POST["submit"]設置..腳本應該是這樣的:

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

    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $message = $_POST['message']; 
    $from = $_POST['name']; 
    $to = '[email protected]'; 
    $subject= 'new enquiry on website'; 
    $subjectf= $_POST['subjectf']; 
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message"; 


    if ($name != '' && $email != '' && $message != '') {   
      if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>'; 
     } else { 
      echo '<p>Something went wrong, go back and try again!</p>'; 
     } 
    } else { 
     echo '<p>You need to fill in all required fields!!</p>'; 
    } 
} 
+0

太棒了!我收到了「您的消息已發送!」但我只是查看了我的電子郵件/垃圾郵件,但它不在那裏。是否有其他設置我必須在php.ini或somthing中更改? – user2291730 2013-05-02 02:39:03

+0

你將需要smtp郵件服務器發送郵件..並取消你的phpini中的smtp和端口25選項.. – Dinesh 2013-05-02 02:39:54

+0

太棒了!謝謝您的幫助! – user2291730 2013-05-02 02:44:19

0

設置您提交的輸入值提交

<input class="submit" type="submit" name="submit" value="submit"> 
+0

還是空白頁 – user2291730 2013-05-02 02:34:24