Very simple PHPmailer Not Working - php

I'm trying to use PHPmailer for the first time and even with a simple set up I am having trouble getting the email to go through. I am using the simple default php mail() function that phpmailer uses, I've used mail() with arguments before on other forms and those emails went through but on this particular site I want to have attachements sent as well. Here is my code so far, note that the attachments, name, email, or checkbox have not been pulled and added to the php code, I'm just getting the darn to work and send whatever is in the textarea. Please help!!!
--HTML-----------------------------------------
<form role="form" action="_/includes/sendmail.php" enctype="multipart/form-data" method="POST" autocomplete="on">
<div class="form-group">
<label class="emph1">First and Last Name:</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="First and Last Name">
</div>
<div class="form-group">
<label class="emph1">Email Address:</label>
<input type="email" class="form-control" id="exampleInputPassword1" placeholder="Email">
</div>
<div class="form-group">
<label class="emph1">File/Form Attachments:</label>
<?php
//Maximum file size (in bytes) must be declared before the file input field and can't be large than the setting for
// upload_max_filesize in php.ini.
// PHP will stop and compain once file is exceeded
// 1 mb is actually 1,048,576 bytes.
?>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<input type="file" id="exampleInputFile" name="file_upload">
<p class="help-block">Please use .jpg, .pdf, or Word based files.</p>
<p> <?php echo $message;?>
</div>
<div class="form-group">
<label class="emph1">Reason for contacting Derek Davis, PLLC:</label>
<div class="checkbox">
<label>Estate Planning<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Family Law<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Criminal Defense<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Collections<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Landlord-Tenant<input type="checkbox"></label>
</div>
<div class="checkbox">
<label>Other<input id="checkbox-other" type="checkbox"></label>
</div>
<!-- jQuery input feature (displays when "other" checkbox is checked) --->
<div class="form-group" id="input-other" style="display:none;">
<label class="emph1" for="">If 'other' please specify:</label>
<input type="text" class="form-control" id="otherProject" name="otherProject" placeholder="Enter short description here." value="" />
</div>
</div>
<!-- End jQuery input feature -->
<div class="form-group">
<label class="emph1">Please leave us a brief message:</label>
<textarea class="full-width" type="text" name="message" rows="10" placeholder="Please be as specific as possible..." required>
</textarea><br />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
--PHPmailer---------------------------
<?php
require_once("_/includes/phpmailer/class.smtp.php");
require_once("_/includes/phpmailer/class.phpmailer.php");
if (isset($_POST['message'])){
$body = $_POST['message'];
}
// Set PHPMailer to use the sendmail transport
//Set who the message is to be sent from
$mail->setFrom('myemail#gmail.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('myemail#gmail.com', 'First Last');
//Set the subject line
$mail->addAddress('myotheremail#yahoo.com', 'John Doe');
$mail->Subject = 'PHPMailer sendmail test';
//Replace the plain text body with one created manually
$mail->Body = $body;
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment($temp_file, $temp_file_name);
//send the message, check for errors
$mail-Send();
?>
Thanks for the quick responses!! I made the changes to send() and initiated the class but it still didn't send crap to my yahoo.com email address. Heres the code now....
<?php
require_once("_/includes/phpmailer/class.smtp.php");
require_once("_/includes/phpmailer/class.phpmailer.php");
$mail = new PHPMailer;
if (isset($_POST['message'])){
$body = $_POST['message'];
}
// Set PHPMailer to use the sendmail transport
//Set who the message is to be sent from
$mail->setFrom('myemail#gmail.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('myemail#gmail.com', 'First Last');
//Set the subject line
$mail->addAddress('myotheremail#yahoo.com', 'John Doe');
$mail->Subject = 'PHPMailer sendmail test';
//Replace the plain text body with one created manually
$mail->Body = $body;
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment($temp_file, $temp_file_name);
//send the message, check for errors
$mail->send();
?>
UPDATE!!!
Ok so here my code now. Not only does it not send a message to my email but it also doesn't redirect me to either page... Any suggestions?
<?php ob_start()?>
<?php
require_once("_/includes/phpmailer/class.smtp.php");
require_once("_/includes/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (isset($_POST['message'])){
$body = $_POST['message'];
}
// Set PHPMailer to use the sendmail transport
//Set who the message is to be sent from
$mail->setFrom('myemail#gmail.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('myemail#gmail.com', 'First Last');
//Set the subject line
$mail->addAddress('myotheremail#yahoo.com', 'John Doe');
$mail->Subject = 'PHPMailer sendmail test';
//Replace the plain text body with one created manually
$mail->Body = $body;
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment($temp_file, $temp_file_name);
//send the message, check for errors
if ($mail->send()) {
redirect_to("../../contact.php");
} else {
redirect_to("../../index.html");
}
?>
<?php ob_end_flush(); ?>

It looks like you never initialized $mail. Add the following line before any of your $mail-> methods. See the example in their documentation.
$mail = new PHPMailer;
To learn more about class constructors, check the PHP documentation.
And you have a typo: $mail-Send(); should be $mail->Send();

Looks like a typo here:
$mail->Send();

//send the message, check for errors
$mail-Send();
should be $mail->send(); ?

As you are using SMTP. The correct way to use smtp is like this
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Related

Php form instead send mail download on computer

<div class="contact_form clearfix" id="Contact">
<h2>Hello... You can send me message to my universe here.</h2>
<img src="img/planeta1.png" alt="">
<form class="clearfix spaceForm" action="contactform.php" metod="post" >
<label for="name">Your name:</label>
<input type="text" name="name" id="name" placeholder="Jon Doe" required>
<label for="email">Your email:</label>
<input type="text" name="email" id="email" placeholder="something#mama.com" required>
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject" required>
<label for="message">Your message:</label>
<textarea name="message" id="message" required></textarea>
<button type="submit" name="submit">Send mail</button>
</div>
and php code here...
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "pisitenam#sammostalnisindikatstark.org.rs";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from " .$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html");
}
?>
My contact form instead to send message download on computer as php file. I uploaded my site to netfly but stil doesnt work.
Can anybody help and give me a hint where is problem?
On XAMPP im getting blank page and mail is not sent. When I uploaded site on netfly site works fine but contact from when click submit start download php file where is code writen for controling contact form.5 day im trying to find solution for this problem and im geting tired :D So if anybody can help...
you are having some spell mistake in your form tag, first of all correct the method spell in your code as it is not correct so it can't redirect and post your data to contact form.
mail library contains various function.
for example:
<?php require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'your_smtp_domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('john#example.net', 'John doe'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
this can works for you if you use library.

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 .

How to send email after I input form? [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 5 years ago.
How to email them after they fill out the form I created, for example
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<input type="text" class="form-control"
id="" value="" name="" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control"
id="" value=""
placeholder="Email">
</div>
<div class="form-group">
<textarea class="form-control" rows="3" placeholder=""
Required autofocus></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-info
btn-block" value="submit">
</div>
</form>
For example, I input this form. After that I can directly email from admin.
And i check my email, i get email "thank you already input".
thanks.
You can use PHPMailer class at https://github.com/PHPMailer/PHPMailer . It allows you to use the mail function or use an smtp server transparently. It also handles HTML based emails and attachments so you don't have to write your own implementation.
Here is an example from the page above:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = '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->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$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';
}
I suggest u use PHP MAILER.
Create a Gmail account and set password application (tutorial)
Use your Gmail u create before use PHP MAILER, remember use password application
You can see example code here

php form - godaddy economic hosting Linux

i have this form:
<form action="/sendemail.php" id="main-contact-form" method="post" name="contact-form" role="form">
<div class="form-group">
<input class="form-control" id="name" name="name" placeholder="put your name" required="" type="text" />
</div>
<div class="form-group">
<input class="form-control" id="email" name="email" placeholder="Email" required="" type="email" />
</div>
<div class="form-group">
<input class="form-control" id="subject" name="subject" placeholder="Subject..." required="" type="text" />
</div>
<div class="form-group">
<textarea class="form-control" name="message" placeholder="Mensaje" required="" rows="8"></textarea>
</div>
<input class="btn btn-primary" id="submit" name="submit" type="submit" value="Enviar" />
and this is sendemail.php:
<?php
$pos = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email'];
$to = 'email#gmail.com ';
$subject = 'contact message ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message\n $pos";
mail ($to, $subject, $body, $from)
?>
the email is arrive empty, i try a lot of stuffs but always comes in the same way, is like the form canĀ“t pass the data from inputs to php variables. im new in php so, any help is welcome.
thanks.
The use of mail() function is so insecure and is a vector attack to send massive spam, don't use anymore, for this reason is better to use PHP Mailer libray.
Create a EMAIL account (example: no-reply#domain.com) in your hosting and after that install this library PHP Mailer, now you can do this:
<?php
require 'PHPMailerAutoload.php';
$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'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$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); // Set email format to HTML
$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';
}
UPDATE
After some research I've found that:
You need to ask godaddy technical support to enable "sendmail".
PHP mail() not working on GoDaddy
----------
I've tested your code and it works. I've received the email with ALL the $_POST contents without any problems.
$pos = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email'];
$to = 'email#gmail.com ';
$subject = 'contact message ';
NOTE:
1 - $pos = $_POST; is an array and it will be displayed as Array.
2 - Emails sent via mail() will most likely end-up on the spam folder (read the comments below).

PHPMailer not sending e-mail through Gmail, returns blank page

I am trying to set up a contact form at the bottom of my page. I am using PHPMailer and trying to receive emails at my gmail account. Every time I submit the form, my url changes to url/email.php and I get a blank page. What am I doing wrong? Can anyone see the glaring error that I am obviously missing?
HTML:
<div class="container-fluid">
<form action="email.php" id="contact-me" method="post" name="contact-me">
<div class="row-fluid">
<div class="form-group">
<div class="col-md-3 col-md-offset-3">
<input class="input" name="name" id="name" placeholder="Name" type="text">
</div>
<div class="col-md-3">
<input class="input" id="email" name="email"
placeholder="Email" type="text">
</div>
</div>
</div>
<div class="form-group">
<textarea class="input input-textarea" id="message" name="message" placeholder="Type your message here" rows=
"5"></textarea>
</div>
<input name="send" class="send" type="submit" value="Get In Touch">
</form>
</div>
</section>
PHP:
<?php
if (isset($_POST['submit']))
{
require('PHPMailer-master/PHPMailerAutoload.php');
require_once('PHPMailer-master/class.smtp.php');
include_once('PHPMailer-master/class.phpmail.php');
$name = strip_tags($_Post['name']);
$email = strip_tags($_POST['email']);
$msg = strip_tags($_POST['message']);
$subject = "Message from Portfolio";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'me#gmail.com';
$mail->Password = '***********';
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress("me.com", "Katia Sittmann");
$mail->AddReplyTo($email, $name);
$mail->isHTML(true);
$mail->WordWrap = 50;
$mail->Subject =$subject;
$mail->Body = $msg;
$mail->AltBody ="No message entered";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}else{
header("Location: thank-you.html");
}
}
?>
You've got some very confused code here. You should start out with an up-to-date example, not an old one, and make sure you're using the latest PHPMailer (at least 5.2.10).
Don't do this:
require('PHPMailer-master/PHPMailerAutoload.php');
require_once('PHPMailer-master/class.smtp.php');
include_once('PHPMailer-master/class.phpmail.php');
All you need is this, which will auto-load the other classes if and when they are needed:
require 'PHPMailer-master/PHPMailerAutoload.php';
This won't work:
$name = strip_tags($_Post['name']);
PHP variables are case-sensitive, so do this:
$name = strip_tags($_POST['name']);
This will cause problems:
$mail->From = $email;
When you do this, you're forging the From address, and it will get rejected by SPF checks. Put your own address in here, and let the reply-to carry the submitter's address, as you're already doing.
Submit may not be included in the submission if the form is not submitted via that control, e.g. if it's submitted by hitting return in a text input. Check for a field that you know will always be in a submission:
if (array_key_exists('email', $_POST)) {...
Adding a try/catch will not achieve anything - PHPMailer does not throw exceptions unless you ask it to, and you are not.
You are applying strip_tags on the body, but then calling $mail->isHTML(true); - do you want HTML or not?
All that said, none of those things will cause a blank page. It's fairly likely you are running into gmail auth problems which are popular lately, and to see that you need to enable debug output:
$mail->SMTPDebug = 2;
and then read the troubleshooting guide on what you see.

Categories