PHP表单发送邮件产生空白输出

时间:2014-01-06 21:12:46

标签: php html forms smtp

当我按下提交时,我将被带到一个空白文档,将我带到/mail.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 = "support@the(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)1966@gmail.com"); //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脚本的开头添加了错误检查,但我只是得到一个空白屏幕。

2 个答案:

答案 0 :(得分:0)

经过一场大挣扎之后,我们所有的头痛事实上都变得非常简单......

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

谢谢大家的帮助,非常感谢!

答案 1 :(得分:-1)

正如您在下面的评论中所讨论的那样,您的托管服务器不支持更改有关错误的PHP配置更改。

此外,您错误地启用了输出缓冲,并且您永远不会刷新缓冲区。它可能会在脚本终止时自动刷新,但我没有设法在文档中找到它。在不需要时关闭输出缓冲更安全。

解决方案应该是删除这三行:

ini_set('display_errors',1); 
error_reporting(E_ALL);
ob_start();
相关问题