2014-01-06 3 views
0

Когда я нажимаю submit, я попадаю в пустой документ, беря меня в место /mail.php. Вот код.PHP-форма отправки почты, производящей пустой вывод

<form action="mail.php" method="post" enctype="multipart/form-data" name="contactform" id="contactform"> 
    <table width="920" height="600" border="0" align="left"> 
     <tr> 
      <th width="450" scope="row"><div align="left"> 
      <label for="firstname"></label> 
      <span id="sprytextfield1"> 
      Full Name<br /> 
      <br /> 
      <input type="text" name="name" id="name" /> 
      <span class="textfieldRequiredMsg">A value is required.</span></span> </div></th> 
      <th width="450" scope="row"><label for="name"></label></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"> 
      <label for="email"></label> 
      <span id="sprytextfield2"> E-Mail Address<br /> 
      <br /> 
      <input type="text" name="email" id="email" /> 
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></div></th> 
      <th scope="row"><div align="left"> 
      <label for="contactno"></label> 
      <span id="sprytextfield3"> Contact Number<br /> 
      <br /> 
      <input type="text" name="contactno" id="contactno" /> 
      <span class="textfieldInvalidFormatMsg">Invalid format.</span></span></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><p align="left">Related Service</p> 
      <p align="left"> 
       <label> 
       <input type="checkbox" name="service" value="Yes" id="service_0" /> 
       Alloy Wheels Repair</label> 
       <br /> 
       <label> 
       <input type="checkbox" name="service1" value="Yes" id="service_1" /> 
       Leather & Cloth Repair</label> 
       <br /> 
       <label> 
       <input type="checkbox" name="service2" value="Yes" id="service_2" /> 
       Paintless Dent Removal</label> 
       <br /> 
       <label> 
       <input type="checkbox" name="service3" value="Yes" id="service_3" /> 
       Panel Repaint</label> 
       <br /> 
      </p></th> 
      <th scope="row"><div align="left"> 
      </div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><p align="left"> 
      <label for="number"></label> 
      Address Area 
      </p> 
      <p align="left"> 
      <input type="text" name="area" id="area" /> 
     </p></th> 
      <th scope="row"><div align="left"> 
      <label> 
       Message<br /> 
       <br /> 
<textarea name="comments" id="message" cols="45" rows="6"></textarea> 
      </label> 
      </div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"></div></th> 
     </tr> 
     <tr> 
      <th scope="row"><div align="left"></div></th> 
      <th scope="row"><div align="left"> 
       <input type="submit" name="btnSubmit" id="btnSubmit" value="Send Message" /> 
      </div></th> 
     </tr> 
    </table> 
</form> 

PHP

<? 
ini_set('display_errors',1); 
error_reporting(E_ALL); 
ob_start(); 
if (isset($_POST['btnSubmit'])) { 
    require("class.phpmailer.php"); 

    $mail = new PHPMailer(); 

    // Your SMTP servers details 

    $mail->IsSMTP();    // set mailer to use SMTP 
    $mail->Host = "localhost"; // specify main and backup server or localhost 
    $mail->SMTPAuth = true;  // turn on SMTP authentication 
    $mail->Username = "[email protected](hidden)x.co.uk"; // SMTP username 
    $mail->Password = "!c(hidden)3"; // SMTP password 
    // It should be same as that of the SMTP user 

    $redirect_url = "http://www.the(hidden)x.co.uk/contactusthanks.html"; //Redirect URL after submit the form 

    $mail->From = $mail->Username; //Default From email same as smtp user 
    $mail->FromName = "Display Name"; 

    $mail->AddAddress("(hidden)[email protected]"); //Email address where you wish to receive/collect those emails. 

    $mail->WordWrap = 50;         // set word wrap to 50 characters 
    $mail->IsHTML(true);         // set email format to HTML 

    $mail->Subject = $_POST['email']; 
    $message = "Name of the requestor :".$_POST['name']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Phone number :".$_POST['contactno']." \r\n <br><br>Alloy Repair :".$_POST['service']." \r\n <br>Seat Repair :".$_POST['service1']." \r\n <br>Dent Repair :".$_POST['service2']." \r\n <br>Panel Repaint :".$_POST['service3']." \r\n <br>Customer Area :".$_POST['area']." \r\n <br><br> Message: ".$_POST['comments']; 
    $mail->Body = $message; 

    if (!$mail->Send()) { 
     echo "Message could not be sent. <p>"; 
     echo "Mailer Error: " . $mail->ErrorInfo; 
     exit; 
    } 

    echo "Message has been sent"; 
    header("Location: $redirect_url"); 
} 
?> 

Я добавил проверку ошибок в начале моего PHP скрипт, но я только получаю пустой экран.

+0

Целью буферизации вывода является? –

+0

Проверьте журнал ошибок сервера. При настройке событий вокруг сообщений об ошибках внутри PHP они иногда вызывают ошибки. Безопаснее поставить 'php_flag display_errors' в ваш Apache' .htaccess', потому что если этот вариант конфигурации отклонен, вы получите 500 ошибок HTTP, и вы знаете, что происходит. – Palec

+0

Это потому, что вы используете ob_start() и сохраняете весь вывод в выходном буфере http://be2.php.net/ob_start – user1026090

ответ

0

После большой борьбы, все наши головные боли оказались на самом деле что-то довольно просто ....

"Michael B: the domain entry was missing on server in below file 
Michael B: /etc/localdomains 
Michael B: I have added the entry" 

Thank- вы все за вашу помощь очень цените!

-1

Как обсуждалось в комментариях к вашему вопросу, ваш хостинг не поддерживает изменение изменений конфигурации PHP в отношении ошибок.

Также вы ошибочно включили буферизацию вывода, и вы никогда не очищаете буфер. Он может автоматически очищаться при завершении сценария, но мне не удалось найти его в документации. Безопаснее отключать буферизацию вывода, когда вам это не нужно.

Решение должно быть удаление этих трех линий:

ini_set('display_errors',1); 
error_reporting(E_ALL); 
ob_start(); 
+0

Как скрыть ошибки решить проблему? Кроме того, выходной буфер, вероятно, покраснет в браузер при завершении скрипта: http://codepad.viper-7.com/lfihze – jeroen

+0

Спасибо за ваш ответ, я удалил эти три строки, и я все равно беру только за пустой стр. Также эти три строки кода находятся в моем другом домене, и форма работает нормально. Это голова! – Metexora

+0

http://pastebin.com/d9dRdy9p удалось получить некоторые ошибки – Metexora

Смежные вопросы