I made an contact form in codeigniter so users can contact me but when I try to send the email nothing is send. I don't know why it happens. Also I know This has been asked before but I only want to know if there's something wrong with my code.
This is my controller:
<?php
class Contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
//$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
//$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
//$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
//$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('contact_form_view');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//naar welk email je het wilt sturen
$to_email = 'ferran1004#gmail.com';
//send mail
$this->load->library('email', $config);
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send() == TRUE)
{
// email sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/index');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/index');
}
}
}
//Alleen alfabet letters en spaties code
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
This is my view:
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 well">
<?php $attributes = array("class" => "form-horizontal", "name" => "Contactform");
echo form_open("Contactform/index", $attributes);?>
<fieldset>
<legend>Contact Form</legend>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
</div>
<div class="col-md-12">
<input class="form-control" name="name" placeholder="Your Full Name" type="text" value="<?php echo set_value('name'); ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email" class="control-label">Email ID</label>
</div>
<div class="col-md-12">
<input class="form-control" name="email" placeholder="Your Email ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="subject" class="control-label">Subject</label>
</div>
<div class="col-md-12">
<input class="form-control" name="subject" placeholder="Your Subject" type="text" value="<?php echo set_value('subject'); ?>" />
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="message" class="control-label">Message</label>
</div>
<div class="col-md-12">
<textarea class="form-control" name="message" rows="4" placeholder="Your Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input name="submit" type="submit" class="btn btn-primary" value="Send" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
This is my email.php file in my config folder:
<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xxxxx#gmail.com'; //change this
$config['smtp_pass'] = 'xxxxxxx'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
?>
When I click on send, no email is send.
you can configure Google SMTP server as follows
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'youremail#gmail.com';
$config['smtp_pass'] = 'youremailpassword';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // html or text
$config['validation'] = TRUE; // bool whether to validate email or not
Google's SMTP server requires authentication, so here's how to set it up:
SMTP server (i.e., outgoing mail): smtp.gmail.com
SMTP username: Your full Gmail or Google Apps email address (e.g example#gmail.com or example#yourdomain.com)
SMTP password: Your Gmail or Google Apps email password
SMTP port: 465
SMTP TLS/SSL required: yes
In order to store a copy of outgoing emails in your Gmail or Google Apps Sent folder, log into your Gmail or Google Apps email Settings and:
Click on the Forwarding/IMAP tab and scroll down to the IMAP Access section: IMAP must be enabled in order for emails to be properly copied to your sent folder.
for more https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server
OR Codeigniter email sending is not working
since this seems to be a matter of urgency because there are a ton of questions lately regarding codeigniter & sending mails, i try to explain what you could do to find out your problem
1. installing PHP Mailer
CI doesn't provide that much information, in order to find out what's wrong with your attempt to send emails - i suggest to use PHP Mailer for that purpose.
Download the latest PHPMailer Build from Github.
You can find the project here
Click now on "clone or download" and download it as zip - as in the image below is shown.
Create a Folder phpmailer where Codeigniters index.php lies.
The root folder in this zip File is called - PHPMailer-master.
Unzip it to your phpmailer directory and rename the folder to lib.
You should see something like
2. Using PHP Mailer
first of all i'm not writing down here what stays in the Documentation or can found elsewhere
The following links are useful for you to study PHPMailer
Troubleshooting
API
Examples
Create a php file called mail.php within your phpmailer directory.
An example could be:
require_once("./lib/PHPMailerAutoload.php");
echo "<pre>";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = '0.0.0.0';
$mail->SMTPAuth = true;
$mail->Username = "yyy";
$mail->Password = "xxx";
$mail->Port = 25;
$mail->SMTPDebug = 2;
$mail->From = 'office#example.com';
$mail->FromName = 'John Doe';
$mail->addAddress('john.doe#example.com', 'John Doe');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if(!$mail->send()) {
echo '<br />Message could not be sent.';
echo '<br />Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
3. Finishing investigating your problem
the most important thing here is, you've to separate your mail problem from Codeigniter. If you manage to send emails via PHP Mailer, it should be easy to integrate it with CI.
As long as you are not able to send these mails, you should debug it
with PHPMailer.
if you call now your mail.php file via browser you should be able to see enough information in order to investigate your problem.
One last word:
look #your spam folder too ;)
change this code in your config email.php:
$config['protocol'] = 'smtp';
to this:
$config['protocol'] = 'mail';
source here
Related
<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.
Hi i am using PHPMailer for my website to send an email but getting error as SMTP Error: Could not authenticate.
This was error which i was getting.I have given the password correct and turned Allow less secure apps to "ON as well but still getting the same error.
020-01-25 09:11:24 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 oCoMr_x13f0BsQ-UMqe0zgPQOcVX9A7SY4fBk-WoLrRIJfT6uwspq7QpzlUjE8srm9esG534-5.7.14 73T38rlSCuGdkDRsjhkB3YQxKz3V8njuaclMAfqHskMAU3eX_1LYPH80oO9ZLkAl>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 i81sm528818ywe.82 - gsmtp
SMTP Error: Could not authenticate.
2020-01-25 09:11:24 CLIENT -> SERVER: QUIT
Here is the code which i have used for sending an email
<?php ob_start();
if(isset($_POST['submit_contact']))
{
require 'PHPMailer/PHPMailerAutoload.php';
$address = 'testing1#gmail.com';
$name=$_POST['name'];
$email =$_POST['email'];
$subject = $_POST['subject'];
$textMessage = $_POST['message'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug =1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->CharSet = "UTF-8";
$mail->IsHTML(true);
$mail->Username = "testing#gmail.com";
$mail->Password = "PASSword1#3";
$message = array();
$message[] = 'Name : '.trim($name).' ';
$message[] = 'Email : '.trim($email).' ';
$message[] = 'Comment : '.trim($textMessage).' ';
$message = implode(',', $message);
$mail->SetFrom($email);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($address);
if (!$mail->Send()) {
$msg = "Error while sending email";
$msgclass = 'bg-danger';
} else {
$msg = 'Thank you for contacting us.Will get back to you soon.....';
$msgclass = 'bg-success';
header("Location: contact.php");
}
}
?>
Here is the HTML Code which i have written
<form class="form-horizontal" action="contactus" method="post" role="form" enctype="multipart/form-data">
<?php if(isset( $msg)) {?>
<div class="<?php echo $msgclass; ?>" style="padding:5px;"><?php echo $msg; ?></div>
<?php } ?>
<div class="form-group">
<input type="text" name="name" id="name" class="form-control input-field" placeholder="Name" required="">
<input type="email" name="email" id="email" class="form-control input-field" placeholder="Email ID" required="">
<input type="text" name="subject" id="subject" class="form-control input-field" placeholder="Subject" required="">
</div>
<textarea name="message" id="message" class="textarea-field form-control" rows="4" placeholder="Enter your message" required=""></textarea>
<button type="submit" id="btnSend" value="Submit" class="btn center-block" name="submit_contact" >Send message</button>
<!-- Contact results -->
</form>
Always look at the information that’s right in front of you.
Read the troubleshooting guide linked from the error message - it tells you exactly how to deal with this precise problem — you most likely need to perform the “display captcha unlock” step.
It’s not just the “less secure apps” setting (which you can avoid by implementing XOAUTH2), it’s also that gmail imposes additional auth steps when logging in through a new mechanism (I.e. your script), which is briefly mentioned in the link they provide in the responses.
I have created a simple html & bootstrap contact form which is backed by PHPMailer class to send an email. The program works perfectly till the sending of email. However, it is not showing the success/failure message on the same page and not clearing the fields also.
The code which I have written for my demo program is below. Please append your solutions to the same code rather making another code of your own.
index.html
<form method="post" action="mail.php" id="contact-form" role="form">
<div class="card-header">
<h2 class="font-weight-bold text-center my-4">Contact us</h2>
<p class="text-center mx-auto mb-5">Do you have any questions? Please do not hesitate to
contact us directly. Our team will come back to you within
a matter of hours to help you.</p>
<div class="alert alert-success" id="success-message"><span>Thank you for contacting us. We will
be in touch
soon.</span></div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group ">
<label for="name" class="is-required">Name</label>
<input type="text" name="name" id="name" class="form-control" minlength="3"
required>
</div>
</div>
<div class="col-md-6">
<div class="form-group ">
<label for="email" class="is-required">email</label>
<input type="email" name="email" id="email" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="message" class="is-required">Message</label>
<textarea name="message" id="message" rows="2" class="form-control"
required></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="text-center text-md-left">
<input type="hidden" name="action" value="sendEmail" />
<button id="submit-button" name="submit" type="submit" value="Send"
class="btn btn-primary"><span>Send</span></button>
</div>
<div class="status" id="status"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="status" id="status"></div>
</div>
</div>
</div>
</form>
jQuery/ajax
<script>
$('form').validate();
$(document).ready(() => {
$('#success-message').hide();
$('form').submit((e) => {
let formData = {
'name': $('#name').val(),
'email': $('#email').val(),
'message': $('#message').val(),
'submit': 1
};
$.ajax({
type: 'POST',
url: 'mail.php',
data: formData,
dataType: 'json',
encode: true
}).done((data) => {
if (data.success) {
$('#success-message').show();
} else {
alert('Something went wrong. Please try again!');
}
});
e.preventDefault();
});
});
</script>
mail.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// header('Content-Type: application/json');
if (isset($_POST['submit'])) {
$name = $_POST['name']; // Sender's name
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$message = $_POST['message']; // Sender's message
$errorEmpty = false;
$errorEmail = false;
if (empty($name) || empty($email) || empty($message)) {
echo "<span class='alert alert-danger'> Name is required.</span>";
$errorEmpty = true;
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<span class='alert alert-danger'> Please try entering a correct email.</span>";
$errorEmail = true;
}
// Instantiate PHPMailer class
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail#gmail.com'; // SMTP username
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('mymail#gmail.com', 'My Name');
$mail->addAddress($email, $name); // Add a recipient
$body = '<p>Hello <strong> Mr. ' . $name . '</strong> <br /><br /> We have received your enquiry "' .$message. '". <br /> We ensure you that the team is working on it. <br /><br /> Thank you. </p>';
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'We received your query.';
$mail->Body = $body;
// $mail->AltBody = strip_tags($body);
$mail->send();
// echo 'Message has been sent';
} catch (Exception $e) {
echo $e->errorMessage();
echo "Mailer Error: " . $mail->ErrorInfo;
}
} else {
echo "There was an error!";
}
?>
Your any help is highly appreciated. Thanks in advance.
You're not really trying here. You're making an XHR, but not even attempting to return the results in a format that will work with that, and neither are you returning an error code that will trigger your error handler. First of all, you need to set the correct content type:
header('Content-type: application/json');
Then handle errors or valid responses apropriately, giving results in JSON format:
} catch (Exception $e) {
//Some other code may be better, but anything other than 2xx will do for jQuery
http_response_code(400);
echo json_encode(['status' => false, 'errormessage' => $e->errorMessage(), 'errorinfo' => $mail->Errorinfo]);
exit;
}
echo json_encode(['status' => true]);
exit;
Note that if your check for isset($_POST['submit']) fails, you should not say anything (you're currently displaying an error) - it's what will happen when they first load the page.
Ive been trying to get my contact form working, but i'm not receiving any emails in my gmail folders (including spam and trash. and also can't track anything through my host).
I've been following this tutorial: http://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form
Need some serious help as i've tried everything!
<?php
$from = $_POST['email'];
$sendTo = 'myemail#gmail.com';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'email' => 'Email', 'phone' => 'Phone', 'message' => 'Message');
// array variable name => Text to appear in email
$okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
// let's do the sending
try
{
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
THE HTML FORM
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>First name*</label>
<input type="text" id="form-name" name="name" class="form- control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Last name*</label>
<input type="text" name="surname" id="form-surname" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>Email*</label>
<input type="email" name="email" id="form-email" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Phone</label>
<input type="tel" name="phone" id="form-phone" class="form- control" placeholder="Please enter your phone">
</div>
</div>
</div>
<div class="form-group">
<label for="comment">Message*</label>
<textarea class="form-control" rows="7" name="message" id="form-message" default="Type us a message" required="required"></textarea>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">Join mailing list</label>
</div>
<input type="submit" class="btm btn-success btn-send" value="Send message">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</form>
As many servers don't allow you to send emails in the name of someone whom is not registered, you should create an email on your server that's only for sending you the emails that your users write once they fill the contact form, then you should use a class like PHPMailer to send the email for you.
A simple example showing how to use PHPMailer would be:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.yourserver.here'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#userserver.here'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('user#userserver.here', 'Mailer');
$mail->addAddress('your#email.here', 'You'); // Add a recipient
$mail->addReplyTo('theuser#email.here', 'User that submitted form');
$mail->Subject = 'Subject here';
$mail->Body = 'Write here your message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
The example is taken from the link I've told you above.
You don't have Mail Delivery error?
Try send email from know host in:
$from = $_POST['email']; (like youremail#gmail.com)
Gmail checks DKIM (posted by) and SPF (signed by) record in DNS server to email host. If email host don't have a DKIM record, email may be not supplied.
More (gmail):
https://support.google.com/mail/answer/180707?hl=en
More (How To Install and Configure DKIM):
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-dkim-with-postfix-on-debian-wheezy
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.