New Era Fuels
New Era Fuels

Reputation: 3

PHPMailer not redirecting after submit

The code works correctly in sending the mail and auto reply to the visitor. However when the form is submitted the page does nothing and just sits on the same page with the form still filled out. It is not redirecting to browser to the "Thank you" page.

I have spend hours on trying to resolve this and cant for the life of me figure out why it wont redirect.

Please someone help!

<?php
require $_SERVER['DOCUMENT_ROOT'].'/assets/class.phpmailer.php';
session_start();

date_default_timezone_set('Europe/London');
$time = date("d/m/y @ H:i:s", time());
$referer = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];

$sendfrom = "[email protected]";
$sendname = "Senders Name";

$name = $_POST['visitor-name'];
$subject = $_POST['visitor-subject'];
$email = $_POST['visitor-email'];
$message = $_POST['visitor-message'];
$phone = $_POST['visitor-phone'];

$mail = new PHPMailer(true);
$mail->SMTPDebug = 0;
$mail->IsSMTP(true);
$mail->Host = "localhost"; //Hostname of the mail server
$mail->Port = '25'; //Port of the SMTP like to be 25, 80, 465 or 587
$mail->ClearReplyTos();
$mail->addReplyTo($email, $name);
$mail->SetFrom($sendfrom, $name); //FROM address and NAME
$mail->AddAddress($sendfrom); //TO address
$mail->Subject = ("Web Form: $subject");
$mail->Body = "MESSAGE";
$mail->IsHTML(true);

//auto reply
if($mail->send()){
    $automail = new PHPMailer(true);
    $automail->SMTPDebug = 0;
    $automail->IsSMTP(true);
    $automail->Host = "localhost"; //Hostname of the mail server
    $automail->Port = '25'; //Port of the SMTP like to be 25, 80, 465 or 587
    $automail->ClearReplyTos();
    $automail->addReplyTo("[email protected]", $sendname);
    $automail->SetFrom($sendfrom, $sendname); //FROM address and NAME
    $automail->AddAddress($email); //TO address
    $automail->Subject = "Thank you for your recent enquiry";
    $automail->Body = "AUTO REPLY MESSAGE";

    $automail->IsHTML(true);

if($automail->Send()) {
    Header("Location: success.php");
    exit;
    }
}
?>

Upvotes: 0

Views: 1180

Answers (1)

user5175220
user5175220

Reputation:

//$mail->SMTPDebug = 0;

That helped me

Upvotes: 1

Related Questions