I'm trying to get a contact form send an email to an inbox with PHPMailer. Once the email is sent or ready to send, I want it to relocate the page to thankyou.php.
The trouble I'm having when clicking my form button: It goes to the mail.php page but it's blank. I have the header at the bottom redirecting the page.
Testing the script on the command line via "php mail.php", returning with no errors, I then receive the email.
Testing the script on a browser brings up white page and no email.
When I remove only the code for PHPMailer but leave my require() statement on the first line and header(Location: thankyou.php), it then redirects me to my thankyou page.
Here's my code:
PHPMailer Code : mail.php
<?php
require('PHPMailer/PHPMailer/PHPMailerAutoload.php');
$mailto = new PHPMailer();
$mailto->SMTPDebug = 2;
$mailto->CharSet = 'UTF-8';
$mailto->isSMTP();
$mailto->Host = "smtp.gmail.com";
$mailto->SMTPAuth = true;
$mailto->Username = "*****@gmail.com";
$mailto->Password = "*****";
$mailto->SMTPSecure = "tls";
$mailto->Port = 587;
$mailto->addAddress('example@gmail.com', 'Joe User');
$mailto->addReplyTo('example@gmail.com', 'Information');
$mailto->setFrom('example@gmail.com', 'Mailer');
$mailto->isHTML(true);
$mailto->Subject = "Testing From Contact Page";
$mailto->Body = "This is the HTML message body <b>in bold!</b>";
$mailto->AltBody = "This is the body in plain text for non-HTML mail clients";
$mailto->Send();
header("Location: http://$URL/thankyou.php");
?>
HTML CODE FOR
<?php
include('navigation.php');
?>
<div id="contact_form_wrapper">
<div class="contact_call">
<div>
<img src="images/icons/icon_call.png" alt="Phone: 555.555.5555" />
<div>
<h2>Call us at 555.555.5555</h2>
<p>
Address Canada<br /><br />
Hours: Monday - Friday 8:00 a.m. to 4:00 p.m.
</p>
</div>
</div>
</div>
<h1>Fill out this form to request more information</h1>
<form name="requestquote" method="POST" action="mail.php">
<!-- onsubmit="return formValidation() -->
<!-- <ul class="request_div">
<li><p>Company Name</p><input type="text" name="company" maxlength="50" size="30"/></li>
<li><p>Full Name</p><input type="text" name="name" maxlength="50" size="30"/></li>
<li><p>Postal Code</p><input type="text" name="zip" maxlength="50" size="30"/></li>
<li><p>Telephone</p><input type="text" name="phone" maxlength="50" size="30"/></li>
<li><p>Email</p><input type="text" name="email" maxlength="50" size="30"/></li>
</ul>
<ul class="div_comment">
<li><p>Request Information</p><textarea name="comments"></textarea></li>
</ul> -->
<div id="btnRequests">
<input type="submit" value="SUBMIT" class="btnStyle1"/>
<input type="reset" value="CLEAR" class="btnStyle1" />
</div>
</form>
<div class="contact_call">
<div>
<img src="images/icons/icon_call.png" alt="Phone: 555.555.5555" />
<div>
<h2>Call us at 555.555.5555</h2>
<p>
Address Canada<br /><br />
Hours: Monday - Friday 8:00 a.m. to 4:00 p.m.
</p>
</div>
</div>
</div>
</div>
<?php
include('footer.php');
?>
I've already tried the following as well:
Checked for White Space around ,
Messed around with Ob_start() Not sure how that really went. didn't do anything to the code.
Tried putting Script tags and adding JS. I couldn't get that to even work. though my other sites have working js. I kind of don't want to go this route.
I've placed exit(); everywhere, as well as die();
Placed and Removed Echo Statements.
Tried installing the PHPMailer with Composer.
Added many various require, require_once, include variations
My Ports are open. The hosting server has all open as I already called them to confirm.
Maybe after all one of the above are right, I've been working on this for three days. Now asking for some help. Let's Chat!