SMTP联络表格提交黑屏(SMTP Contact Form blank screen on Sub

2019-10-19 04:30发布

我一直有与接触形式的问题很多,没有人知道为什么我的代码只是造就了一个空白屏幕“(URL)/mail.php当我按下提交我的形式。

这里是我的代码

 <h2 class="formhead">Contact Form</h2>
<br>
  <form class="form" action="mail.php" method="post">

    <p class="name">
        <input type="text" name="name" id="name" placeholder="John Doe" />
        <label for="name">Name</label>
    </p>
<br>
    <p class="email">
        <input type="text" name="email" id="email" placeholder="mail@example.com" />
        <label for="email">Email</label>
    </p>
<br>
    <p class="number">
        <input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
        <label for="name">Contact Number</label>
    </p>
<br>
    <p class="web">
        <input type="text" name="web" id="web" placeholder="www.example.co.uk" />
        <label for="name">Website</label>
    </p>
<br>
    <p class="query">
        <textarea name="query" id="query" placeholder="Write something to us" /> </textarea>
    </p>
<br>
    <p class="submit">
        <input name="btnSubmit" type="submit" onclick="javascript: return validate();"  value="Send" />
    </p>
  </form>

PHP

<?
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 = "supp0rt@c(hidden)y.co.uk";  // SMTP username
$mail->Password = "DQ(hidden)"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

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

$mail->AddAddress("enquiries@c(hidden)y.co.uk", "chapnolo"); //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['number']."\r\n <br> Message: ".$_POST['query']."\r\n <br> Website: ".$_POST['web'];
$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。

Answer 1:

这不是能够找到PHP邮件类class.phpmailer.php。 它是在同一个目录中的文件的其余部分..?



Answer 2:

我会移动的header()调用的外部if()语句,以确保一个人总是重定向:想想会发生什么,如果是手动访问一个人yoursite.com/mail.php不使用你的表单POST数据:

<?PHP
ob_start();
if(isset($_POST['btnSubmit']))
{
    // Mail stuff
}
header("Location: $redirect_url");
?>


文章来源: SMTP Contact Form blank screen on Submit