简体   繁体   中英

Form Submit displaying blank page with php file in the URL

I can't seem to find the solution for this or an answer online.

It is using Bootstrap and PHPmailer.

Below is my HTML for the form:

<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>

and here is the php script in the "coming-soon-form.php" file:

<?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);

?>

I also have validation through jquery-validation which works fine.

However, once the form is filled out and submitted, it doesn't properly execute, send an email, or display any error or success message on the page as it should. Instead, it simply loads a blank page and the URL is www.domainnamehere.com/_lib/coming-soon-form.php

I also validated all the php using a validator.

What is causing the form submit issue???

Below is the error log information:

[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

The following line is not a valid PHPMailer method:

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

The line below is the correct way to add a recipient.

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

This is the correct way to send email with the 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';
}

please consider about your usage of $mail->From and $mail->To method .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM