簡體   English   中英

表單提交顯示空白頁面,URL中包含php文件

[英]Form Submit displaying blank page with php file in the URL

我似乎找不到在線解決方案或答案。

它正在使用Bootstrap和PHPmailer。

以下是表單的HTML:

<div class="row">
          <div class="col-md-8 col-md-offset-2">
            <div class="row">
              <form name="coming-soon-form" role="form" autocomplete="off" class="m-t-15" id="coming-soon-form" action="_lib/coming-soon-form.php" method="post">
              <div class="row">
                <div class="col-sm-6">
                  <div class="form-group form-group-default required">
                    <label class="control-label">First name</label>
                    <input type="text" id="name" name="name" class="form-control" required>
                  </div>
                </div>
                <div class="col-sm-6">
                  <div class="form-group form-group-default">
                    <label class="control-label">Last name</label>
                    <input type="text" id="last-name" name="last-name" class="form-control" required>
                  </div>
                </div>
              </div>
              <div class="form-group form-group-default">
                <label class="control-label">Email</label>
                <input type="email" id="email" name="email" placeholder="abc@123.com" class="form-control" required>
              </div>
              <div class="sm-p-t-10 clearfix">

                <input type="submit" class="btn btn-complete font-montserrat all-caps fs-12 pull-right xs-pull-left" value="Submit">
              </div>
              <div class="clearfix"></div>
            </form>
            </div>
          </div>
        </div>

這是“ coming-soon-form.php”文件中的php腳本:

<?php 

require 'phpmailer/PHPMailerAutoload.php';

// CONFIG YOUR FIELDS
//============================================================
$name =     filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email =    filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);


// CONFIG YOUR EMAIL MESSAGE
//============================================================
$message = '<p>The following request was sent from: </p>';
$message .= '<p>Name: ' . $name . '</p>';
$message .= '<p>Email: ' . $email . '</p>';
$message .= '<p>Message: ' . $formMessage .'</p>';

// CONFIG YOUR MAIL SERVER
//============================================================
$mail = new PHPMailer;
$mail->isSMTP();                                    // Enable SMTP authentication
$mail->SMTPAuth = true;                             // Set mailer to use SMTP
//Sign up with MAIL GUN
$mail->Host = 'smtp.gmail.com';                // Specify main and backup server (this is a fake name for the use of this example)             

$mail->Username = 'email@gmail.com';                  // SMTP username
$mail->Password = 'password';                         // SMTP password
$mail->SMTPSecure = 'tls';                          // Enable encryption, 'ssl' also accepted                                   
$mail->Port = 587;                        

$mail->From = $email;
$mail->FromName = $name;
$mail->AddReplyTo($email,$name);
$mail->to('email@gmail.com');
$mail->addAddress('email@gmail.com');  // Add a recipient

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

$mail->Subject = 'Contact request';
$mail->Body    = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    $data['error']['title'] = 'Message could not be sent.';
    $data['error']['details'] = 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

$data['success']['title'] = 'Message has been sent';

echo json_encode($data);

?>

我也可以通過jquery-validation進行驗證,效果很好。

但是,一旦表單被填寫並提交,就不能正確執行,發送電子郵件或在頁面上顯示任何錯誤或成功消息。 相反,它僅加載空白頁,URL為www.domainnamehere.com/_lib/coming-soon-form.php

我還使用驗證器驗證了所有php。

是什么導致表單提交問題???

下面是錯誤日志信息:

[23-Aug-2017 03:25:02 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0 [23-Aug-2017 03:25:02 UTC] PHP Fatal error: Uncaught Error: Call to undefined method PHPMailer::to() in /home4/anabasi2/public_html/_lib/coming-soon-form.php:34 Stack trace: #0 {main} thrown in /home4/anabasi2/public_html/_lib/coming-soon-form.php on line 34

以下行不是有效的PHPMailer方法:

$mail->to('email@gmail.com');

下面的行是添加收件人的正確方法。

$mail->addAddress('email@gmail.com');

這是使用PHPMailer發送電子郵件的正確方法:

$mail = new PHPMailer;
//$mail->SMTPDebug = 3;               // Enable verbose debug output
$mail->isSMTP();                 // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  
$mail->SMTPAuth = true;                              
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                           
$mail->Port = 587;                                   

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

請考慮您對$ mail-> From和$ mail-> To方法的用法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM