0

I've been struggling with this form function for the past couple of days and I'm close to having it done! When I click the submit button I just get a blank white screen instead of a pop up of a thank you note and I also dont get an email as I should so I know something is off.

ive tried isset() and messing around with xampp but now I have the site being hosted and I'm running into the white screen

This is the php

    <?php 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';


$DATE = htmlspecialchars($_POST['DATE']);
$TIME = htmlspecialchars($_POST['TIME']);
$NAME = htmlspecialchars($_POST['NAME']);
$ORDER = htmlspecialchars($_POST['ORDER']);
$EMAIL = htmlspecialchars($_POST['EMAIL']);

$mail = new PHPMailer;

$mail->From = "$EMAIL";
$mail->FromName = "$NAME";

$mail->addAddress("ric*****@gmail.com"); 

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "$DATE $TIME \n\r $NAME \n\r $ORDER";
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}
?>

I want the pop up contact message to appear and an email received to the one listed

  • 1
    You should have to learn [this](https://stackoverflow.com/questions/13837375/how-to-show-an-alert-box-in-php) before showing alert. – TarangP Feb 13 '19 at 06:18
  • oh, thanks! any thoughts on the email part? – Ricky Jaime Feb 13 '19 at 06:20
  • 1
    Yes this header is not perfect for sending a valid email.use [this](https://stackoverflow.com/questions/566182/complete-mail-header) header for email. – TarangP Feb 13 '19 at 06:21
  • Instead of using the low level mail-function, I would recommend using one of the tried and tested mail libraries, like PHPMailer, SwiftMailer or similar. Those won't only give you a way more verbose API, you will also easily be able to use SMTP instead (which is recommended) and you won't be dependent on server configuration. – M. Eriksson Feb 13 '19 at 06:25
  • Btw, you should not use the user data as "from" since that's basically forgery (you are sending the mail pretending to be another user). Many mail servers do check if the server it's sent from is allowed to send from that address. If not, the mail will be stuck in the spam folder or even auto deleted. – M. Eriksson Feb 13 '19 at 06:30
  • TarangP - I updated what you had mentioned but I am still getting a blank white screen. – Ricky Jaime Feb 13 '19 at 06:30
  • No luck, I'm still getting a White Screen and no email. I updated the php to show what I currently have – Ricky Jaime Feb 13 '19 at 07:00
  • do you have php display_errors set to On? so you can see what is actually happening? Or did you look in the error_log and check what is there? – Cornel Raiu Feb 13 '19 at 07:07

1 Answers1

0

Sorry I don't have enough reputation to comment yet.

A blank page could be the sign of an uncaught Exception: http://php.net/manual/en/language.exceptions.php

try to catch it and var_dump it (page above has samples)

   try {
    //code here
   } catch (\Exception $e) {
    var_dump($e->getMessage());
   }

This will catch any Exception, in this case for debugging I think that is what you want.

Error should appear in your logs as well.

slayergirl
  • 29
  • 3