Jump to content

How to redirect a Contact Form once submitted?


Acknowledged74

Recommended Posts

Hi

 

We have a nicely working smtp contact form, however the form redirects to the contact.php file as default I presume, when we want it to go to a thank you page. Can you [please take a look at the code below and clarify where I need to put the thank you page URL;

 

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

$mail->From = $mail->Username;    //Default From email same as smtp user
$mail->FromName = "Mobile website";

$mail->AddAddress("[email protected]", "Mobile Website"); //Email address where you wish to receive/collect those emails.

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $_POST['Enquiry'];
$message = "Name: ".$_POST['name']." \r\n <br>Email Address: ".$_POST['email']." \r\n <br> Phone: ".$_POST['phone']." \r\n <br> Vehicle: ".$_POST['select']." \r\n <br> Dates: ".$_POST['dates'];
$mail->Body    = $message;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
header("Location: $redirect_url");
}
?>

 

I have tried replacing the http:// but this returns a page underfined error on submission?

 

We appreciate your help on this one guys :0)

 

Ash

 

---

The redirect happens here:

header("Location: $redirect_url");

To redirect to a different page, you'll need to modify the entire value of $redirect_url. More information about the header() function can be found here:

http://php.net/manual/en/function.header.php

("Location:http://www.thankyou.com") didn't redirect and actually stopped the functionality of the form completely.

 

At the moment, as I said it redirects to contact.php which from a viewer point of view isn't meant to be viewed.

 

I really need this to work guys any other ideas please ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.