Log in

View Full Version : php contact form with no thank you



nate51
08-15-2011, 02:57 PM
I have a feeling this is a simple fix, but I am having some trouble with this one. I have a contact form that I do not want going to a "thank you" page.

Here is the code I am using on the php sending page

<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$to = "xxxx@xxxx.com";
$ToName = "My Name";
$date = date("m/d/Y H:i:s");
$ToSubject = "Email From $name";
$EmailBody = "Sent By: $name at $email
<br /><br />
Message Sent:
<br />$message<br /><br />";
$message = $EmailBody.$EmailFooter;
mail($to, $ToSubject, $message, $headers . "From:$name <".$email.">");
header("Location:thankyou.html");

?>

I pulled out [header("Location:thankyou.html");] but when I hit the submit button the page opens my send.php page.

I want to be able to hit the submit button and just have the data pass to email without the form page changing as I am usng jQuery to change the div contents. *The site is a single page with jQuery for scrolling.

If anyone knows how to stop the page from changing when I hit submit, that would be great.

*Note: I did try changing 'thankyou.html' to the current page name, but since it is a single page with animated scroll it refreshes the whole page so the jQuery div change doesnt apply and the form resests.

bluewalrus
08-15-2011, 03:09 PM
The form will need to reload to process this unless you send it as an ajax request. Commenting/removing the header line should leave you on the page you are sending the email on.

JShor
08-15-2011, 04:39 PM
Yes, use ajax for this. Post your entire code (the form HTML as well).

nate51
08-16-2011, 02:18 PM
I tried removing the header line and it was then loading the php page that sends the form data so my site would jump from my site to a white page with the php code displayed. I just put the form in an iframe, much easier for me to work with and it works the way it should, with field validation checks and all.