Send Thank you email with phpmailer - php

i have a phpmailer form that is sending email perfectly fine however a I would like to send 2 emails per form submit. The first email should be the form field values to myself. Thsi works as expected. I am having toruble finding any documentation that would allow me to send a second email to the person who submitted the form to say thanks for contacting us we will be in touch shortly. I basically would like to send a second email to the value you $_POST['email'] with "Thank You" as the contents.
The form code (without any thank you email):
require 'library/extensions/PHPMailerAutoload.php';
$mail = new PHPMailer;
$strMessage = "";
//Only action if the form has been submitted
if(isset($_POST['submit-contact-new'])) {
//Validate the fields again, because not everyone has Javascript, including bots
if (isset($_POST['name']) && $_POST['name'] !== "" &&
isset($_POST['surname']) && $_POST['surname'] !== "" &&
isset($_POST['email']) && $_POST['email'] !== "" &&
isset($_POST['phone']) && $_POST['phone'] !== "" &&
isset($_POST['comment']) && $_POST['comment'] !== "") {
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#domain.com'; // SMTP username
$mail->Password = 'passwd'; // SMTP password
$mail->From = 'noreply#domain.com';
$mail->FromName = 'Domain';
$mail->addAddress('staffmember#domain.com', 'First Last'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Domain Form Enquiry';
$mail->Body = '
<html>
<body>
<h1>Domain Website Enquiry</h1>
<p>Information on form was:</p>
<p><strong>Name</strong>: '.$_POST['name'].'</p>
<p><strong>Surname</strong>: '.$_POST['surname'].'</p>
<p><strong>Email</strong>: '.$_POST['email'].'</p>
<p><strong>Phone</strong>: '.$_POST['phone'].'</p>
<p><strong>Enquiry</strong>: '.$_POST['comment'].'</p>
</body>
</html>
';
if(!$mail->send()) {
//Finally redirect
header('Location: '.$_SERVER['REQUEST_URI']. '?message='.$strMessage) ;
} else {
//Finally redirect
header('Location: http://domain.com/thank-you?location='.$strLocation) ;
}
} else {
//Something is wrong, so work out what
if (!isset($_POST['name']) || $_POST['name'] === "") $strMessage .= "<li>Name must be entered</li>";
if (!isset($_POST['surname']) || $_POST['surname'] === "") $strMessage .= "<li>Surname must be entered</li>";
if (isset($_POST['surname']) && isset($_POST['surname']) && $_POST['name'] === $_POST['surname']) $strMessage .= "<li>Name and Surname must be different</li>";
if (!isset($_POST['phone']) || $_POST['phone'] === "") $strMessage .= "<li>Phone Number must be entered</li>";
if (!isset($_POST['email']) || $_POST['email'] === "") $strMessage .= "<li>Email must be entered</li>";
if (!isset($_POST['comment']) || $_POST['comment'] === "") $strMessage .= "<li>An enquiry must be entered</li>";
if ($strMessage !== "") $strMessage = "<ul>" . $strMessage . "</ul>";
//Finally redirect
header('Location: '.$_SERVER['REQUEST_URI']. '?message='.$strMessage) ;
exit();
}
}
?>

To resolve this issue I simply put another instance within this form action and ran phpmailer twice. This enabled me to set seperate body contents and reciepts using the same post content.
<?php
require 'library/extensions/PHPMailerAutoload.php';
$mail = new PHPMailer;
$strMessage = "";
//Only action if the form has been submitted
if(isset($_POST['submit-contact-new'])) {
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#domain.com'; // SMTP username
$mail->Password = 'passwd'; // SMTP password
$mail->From = 'noreply#domain.com';
$mail->FromName = 'Domain';
$mail->addAddress('staff#domain.com', 'Staff Name'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Domain Form Enquiry';
$mail->Body = '
<html>
<body>
<h1>Domain Website Enquiry</h1>
<p>Information on form was:</p>
<p><strong>Name</strong>: '.$_POST['name'].'</p>
<p><strong>Surname</strong>: '.$_POST['surname'].'</p>
<p><strong>Email</strong>: '.$_POST['email'].'</p>
<p><strong>Phone</strong>: '.$_POST['phone'].'</p>
<p><strong>Enquiry</strong>: '.$_POST['comment'].'</p>
</body>
</html>
';
if(!$mail->send()) {
//Finally redirect
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//Finally redirect
header('Location: http://domain.com/thank-you?location='.$strLocation) ;
}
}
$mail = new PHPMailer;
$strMessage = "";
//Only action if the form has been submitted
if(isset($_POST['submit-contact-new'])) {
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#rdomain.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->From = 'noreply#domain.com';
$mail->FromName = 'Domain';
$mail->addAddress(''.$_POST['email'].''); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Thank you for contacting Domain';
$mail->Body = 'Thanks for getting in touch. Your message has been received and will be processed as soon as possible.';
if(!$mail->send()) {
//Finally redirect
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//Finally redirect
header('Location: http://domain.com/thank-you?location='.$strLocation) ;
}
}
?>

Related

Google reCaptcha v2 PHP - works only with file_get_contents()

I am new to PHP and trying to implement Google reCaptcha v2 using PHP and AJAX using either CurlPost() or SocketPost() methods. Currently everything runs fine with file_get_contents() but my provider is going to lock it down soon so I need to refactor my code. Somehow I ran into problem with implementing CurlPost() or SocketPost() - whenever I try to use either of them, nginx responds with 403 stating that Not a POST request (it is hardcoded in one of the else clauses).
What exactly did I overlook with POST? Below are two pieces of code, one is working perfectly with file_get_contents() and second is code in question throwing 403.
Working one
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require("PHPMailer.php");
require("Exception.php");
require("SMTP.php");
require('recaptcha-master/src/autoload.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST["tel"]);
$message = trim($_POST["message"]);
$recaptchaSecret = "6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf";
$captcha = '';
if(isset($_POST["captcha"]) && !empty($_POST["captcha"])){
$captcha=$_POST["captcha"];
}
if(!$captcha){
echo 'Prove that you are human';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf&response=".$captcha."&remoteip=".$_SERVER["REMOTE_ADDR"]);
$obj = json_decode($response);
if($obj->success == true) {
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR empty($tel) OR empty($captcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Build the email content.
$email_content = "Имя: $name\n";
$email_content .= "Телефон: $tel\n";
$email_content .= "Email: $email\n";
$email_content .= "Сообщение: $message\n";
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
//$mail->setFrom($name, $email);
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo "success";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "Something went wrong. Please try again";
}
?>
And not working, giving 403:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require("PHPMailer.php");
require("Exception.php");
require("SMTP.php");
require('recaptcha-master/src/autoload.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST["tel"]);
$message = trim($_POST["message"]);
$recaptcha = $_POST["g-recaptcha-response"];
$secret = '6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf';
}
//$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR empty($tel) OR empty($recaptcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Build the email content.
$email_content = "Имя: $name\n";
$email_content .= "Телефон: $tel\n";
$email_content .= "Email: $email\n";
$email_content .= "Сообщение: $message\n";
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo "success";
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "Something went wrong. Please try again";
}
?>
Really thankful for any hints! Thank you in advance.
Finally I found working solution with curl not using standard google recaptcha library, just plain curl. The code needs a lot of cleaning but it's working. Here it is:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require('PHPMailer.php');
require('Exception.php');
require('SMTP.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = strip_tags(trim($_POST['name']));
$name = str_replace(array('\r','\n'),array(' ',' '),$name);
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST['tel']);
$message = trim($_POST['message']);
$secret = '6LcjwkUUAAAAAENXwZtla40jNuPJGblZkYxLkXvf';
$captcha = '';
if(isset($_POST['captcha']) && !empty($_POST['captcha'])){
$captcha=$_POST['captcha'];
}
if(!$captcha){
echo 'Prove that you are human';
exit;
}
$fields = array(
'secret' => $secret,
'response' => $_POST['captcha'],
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$verifyResponse = curl_init('https://www.google.com/recaptcha/api/siteverify');
curl_setopt($verifyResponse, CURLOPT_RETURNTRANSFER, true);
curl_setopt($verifyResponse, CURLOPT_TIMEOUT, 15);
curl_setopt($verifyResponse, CURLOPT_POSTFIELDS, http_build_query($fields));
$responseData = json_decode(curl_exec($verifyResponse));
curl_close($verifyResponse);
if ($responseData->success) {
if ( empty($name) OR empty($message) OR empty($tel) OR empty($captcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo 'Oops! There was a problem with your submission. Please complete the form and try again.';
exit;
}
// Build the email content.
$email_content = 'Имя: $name\n';
$email_content .= 'Телефон: $tel\n';
$email_content .= 'Email: $email\n';
$email_content .= 'Сообщение: $message\n';
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo 'success';
}
} else {
http_response_code(403);
echo 'Something went wrong. Please try again';
}
?>

SMTP -> ERROR: Failed to connect to server: Connection refused (111) with zoho mail

I am using this code on my server for sending mail, but not respond properly
<?php
function smtpmailer($to, $subject, $body)
{
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.zoho.com';
$mail->Port = 587;
$mail->Username = "contactform#abc.com";
$mail->Password = "********";
$mail->SetFrom("contactform#abc.com", 'af');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->isHTML(true);
$mail->AddAddress($to);
$mail->headers = "Content-type: text/html; charset=utf-8 \r\n";
$mail->headers = "Content-type: image";
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo $error;
$error_no = 0;
} else {
$error_no = 1;
}
return $error_no;
}
if(isset($_POST['Submit']))
{
$name = $_POST['name'];
$email=$_POST['email'];
$msg = $_POST['comment'];
$error = $nameErr = $emailErr = $msgErr = "";
if(empty($name) && empty($email) && empty($msg))
{
$error ="please fill all fields";
}
else
{
if($name == "")
{
$nameErr = "Please enter your name";
}
else
{
if(!preg_match("/^[a-zA-Z ]*$/",$_POST['name']))
{
$nameErr = "only letters and white spaces are allowed";
}
}
if($email == "")
{
$emailErr = "please enter your email";
}
else
{
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid Email Id";
}
}
}
if(empty($error) && empty($nameErr) && empty($emailErr) && empty($msgErr))
{
$message = '';
$message .= '
<p>Hello,</p>
<h4>We have recicved new contact request. Follwoing are detials. </h4>
<table border=0>
<tr><td>Name -- </td><td>'.$name.'</td></tr>
<tr><td>Email ID -- </td><td>'.$email.'</td></tr>
<tr><td>Message -- </td><td>'.$msg.'</td></tr>
</table>
<p>Reagrds, <br/>Flxpert Team</p>';
$to = 'vcv#outlook.com';
$sub = 'New contact request has logged.';
$to1=$email;
$subject1="Contact Successfull.";
$msg1 = '';
$msg1 = '<p>Hello '.ucfirst($name).',</p>
<table border=0>
<tr>
<td>Your contact request has successfully submitted. We will contact you as soon as possiable.</td>
</tr>
</table>
<p>Reagrds, <br/>Flxpert Team</p>';
smtpmailer($to, $sub, $message);
if( smtpmailer($to1, $subject1, $msg1) ){
$success="Your contact request has successfully submitted. We will contact you as soon as possiable. ";
} else{
$error="Something went wrong... ";
}
}
}
?>
It seems you are using PHPMailer library to send out mails & along with that using mail() function at the same time while executing request to send mail. Let's discuss this more in detail so you will come to know why is it happening?
You haven't shown all of your code in correct format and even the form is missing to trace the issue. However there are some points i think could be a problem and those are as follows
Add this before IsSMTP();
$mail = new PHPMailer;
USE
$mail->SMTPSecure = 'tls';
INSTEAD OF (SSL is used for Receiving mail not for sending)
$mail->SMTPSecure = 'ssl';
Remove the mail() function used within your PHPmailer function and try sending mail if it works then try implementing mail() function once the PHPmailer function ends.
Quick Note: You can add multiple PHPmailer function at the same time.
If ended up in no luck, try adding entire code in proper format along with form so will help you to track the issue.

My form will not submit on the website. It just shows blank page at mail.php

What am I doing wrong. There is a html form that takes three inputs Name, Notes, and Phone. The action on the form is mail.php and method is POST.
Here is the code in mail.php. On success I want it to return to homepage.
<?php
// multiple recipients
//$to = 'waleed.dogar#gmail.com' . ', '; // note the comma
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('/phpmailer/class.phpmailer.php');
require_once('/phpmailer/class.smtp.php');
$mail = new PHPMailer();
$mail->Subject = 'Form Submission on Website';
$name = $_REQUEST['name'] ;
$notes = $_REQUEST['notes'] ;
$phone = $_REQUEST['phone'] ;
$body = "You have received a new message from $name.\n". "Here is the phone number:\n $phone". "Here are the additional notes: \n $notes";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtpout.secureserver.net"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtpout.secureserver.net"; // sets the SMTP server
$mail->Port = 80; // set the SMTP port for the GMAIL server
$mail->Username = "alex#acemobiledetailing.ca"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->SetFrom('example#example.ca', 'Alex Website');
$mail->AddReplyTo("example#example.ca","Alex ");
$mail->MsgHTML($body);
$address = "example#gmail.com";
$mail->AddAddress($address, $name);
$mail-> Send();
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
GOTO(http://example.com/thankyou.php);
}
?>

Two versions of same email to two different recipients using class.phpmailer.php

I'm trying to send two versions of the same email to two recipients using phpMailer
Depending on the email I need to send one version or another.
At the moment I'm able to send only the same version to both email address
<?php
require_once('class.phpmailer.php');
if(isset($_POST['Submit'])) {
$fname = $_POST['fname'];
$maileremail = $_POST['maileremail'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer();
$text = 'The person that contacted you is '.$fname.' E-mail: '.$maileremail.' Subject: '.$subject.' Message: '.$message.' :';
$body = eregi_replace("[\]",'',$text);
$text2 = 'The person that contacted you is '.$fname.' E-mail: REMOVED - To get email address you must login Subject: '.$subject.' Message: '.$message.' :';
$body2 = eregi_replace("[\]",'',$text2);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "xxxxx.xxxxx.xxx"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
$mail->Host = "xxxxx.xxxxx.xxx"; // sets the SMTP server
$mail->Port = XXXXXXXX; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxx#xxxxx.xxx"; // SMTP account username
$mail->Password = "XXXXXXXX"; // SMTP account password
$mail->SetFrom('xxxxx#xxxxx.xxx', 'XXXXXXXX');
$mail->Subject = $subject;
$add = array("first#email.xxx", "second#email.xxx");
foreach($add as $address) {
if($address == "first#email.xxx") {
$mail->AddAddress($address, "xxxxxxxxx");
$mail->Body = $body;
}
elseif($address == "second#email.xxx") {
$mail->AddAddress($address, "xxxxxxxxx");
$mail->Body = $body2;
}
}
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "<h3><b>Message sent!</b></h3>";
}}?>
If you're looking to do all the setup once for minimal repetition, simply clone your $mail object in your foreach($add) loop:
foreach ( $add as $address ) {
$current = clone $mail;
if ( $address == 'first#mail.com' ) {
$current->AddAddress($address, "xxxxxxxxx");
$current->Body = $body;
$current->send();
} elseif....
This creates a separate clone of your $mail object for every loop, allowing you to add different email bodies, subjects, etc. without having to rewrite all connection settings.
I think you want to seach the $maileremail inside $add and send the desired email.
$add = array("first#email.xxx", "second#email.xxx");
$mail->AddAddress($maileremail, "xxxxxxxxx");
if($maileremail === $add[0])
$mail->Body = $body;
if($maileremail === $add[1])
$mail->Body = $body2;
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "<h3><b>Message sent!</b></h3>";
}
EDITED:
I misunderstood the question. Brian is right.

Will not redirect after submitting form - Form works, still get error

I have written this form, and it works perfectly. It sends the email fine. But after it sends, it errors. So people submitting the form think its broken, but it actually sends the form. All I am trying to do is redirect after the form submits to thanks.asp after the mail sends.
Any help is appreciated.
<?php
$name = trim($_POST['name']);
$company = $_POST['company'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$site_owners_email = 'support#macnx.com'; // Replace this with your own email address
$site_owners_name = 'Landin'; // replace with your name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 3) {
$error['comments'] = "Please leave a comment.";
}
if (!$error) {
require_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $name;
$mail->Subject = "Website Contact Form";
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->Body = $email . $company . $comments;
// GMAIL STUFF
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "inquiry#getgearhead.com"; // SMTP username
$mail->Password = "..."; // SMTP password
$mail->Send();
header("Location: http://www.macnx.com/noflash/thanks.asp");
}
?>
I believe the problem is that you use header(); incorrectly.
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
PHP Documentation - header
i advice you to use javascript for redirection
just change this :
header("Location: http://www.macnx.com/noflash/thanks.asp");
to this :
echo '<script>
window.location.href = "http://www.macnx.com/noflash/thanks.asp";
</script>';

Categories