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");
}
?>