ashbullmanuk Posted November 5, 2009 Report Posted November 5, 2009 Hi, I am am trying to set up a web site and on the site I have a couple of forms I created in DW, and a PHP script to send the data via email. Easy enough! However I have an issue, the PHP script will only divert to the success url if the user enters data into all the form elements. However, there are no required fields in the form, the script does send the email irrespective of data input into the form, it just doesn't divert to the success URL. Can anyone please give me some advice on this???? Thanks in advance! Quote
virtual Posted November 5, 2009 Report Posted November 5, 2009 You will need to provide a link to your page or at least provide the code that you are having an issue with. Quote
jlhaslip Posted November 6, 2009 Report Posted November 6, 2009 A link won't work. The code is needed since there is php involved. Quote
virtual Posted November 6, 2009 Report Posted November 6, 2009 Quite right, sorry for my slip up, I should have remembered that PHP doesn't show up in source code before I posted, I get those moments sometimes..! Quote
ashbullmanuk Posted November 6, 2009 Author Report Posted November 6, 2009 Quite right!! the code for the php is: <?php /* Subject and Email Variables */ $email_to = "enquiries@kyu-images.com"; $email_subject = "General Enquiry"; $thankyou_url = "http://www.kyu-images.com/contact-us/email_sent.html"; /* Gathering Data Variables */ $nameField = $_POST["name"]; $email_from = $_POST["email"]; $address1Field = $_POST["address1"]; $address2Field = $_POST["address2"]; $townField = $_POST["town"]; $postcodeField = $_POST["postcode"]; $phoneField = $_POST["phone"]; $serviceField = $_POST["service"]; $brochureField = $_POST["brochure"]; $aboutusField = $_POST["aboutus"]; $oursiteField = $_POST["oursite"]; $commentsField = $_POST["comments"]; $headers = "From: $email_from . \r\n"; $headers .= "Reply-To: $email_from . \r\n"; $headers .= "Content-type: text/html\r\n"; $message = << Name: $nameField Email: $email_from First Address Line: $address1Field Second Address Line: $address2Field Address Town: $townField Postcode: $postcodeField Telephone: $phoneField Service Enquiry: $serviceField Send Brochure: $brochureField How Did They Find Us: $aboutusField Did They Like Our Site: $oursiteField Client Comments: $commentsField EOD; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from); /*Results Rendered As HTML */ if($sent) { header("Location: " . $thankyou_url); // Redirect customer to thankyou page } else { // The mail didn't send, display an error. echo "There has been an error sending your message. Please try later."; } ?> Quote
Wickham Posted November 6, 2009 Report Posted November 6, 2009 In your post of the PHP code you have:- $sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from); /*Results Rendered As HTML */ if($sent) { header("Location: " . $thankyou_url); Is /*Results Rendered As HTML */ something you only put in the post or is it in the PHP code? If so it should be //Results Rendered As HTML :- $sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from); //Results Rendered As HTML if($sent) { header("Location: " . $thankyou_url); because the way it is now the code will send the email and stop before it gets to the if($sent) I don't fully understand the $message = Shouldn't that be in " like $message = "EOD..............EOD"; Quote
jlhaslip Posted November 6, 2009 Report Posted November 6, 2009 The Comment block should be fine there. /* * This is the main page comment block. * This page includes the configuration file, * the templates, and any content-specific modules. */ Single line comments are the double slash. Echo the value of $sent right after the mail function to see what it contains. Do you have errors set to display? Quote
ashbullmanuk Posted November 8, 2009 Author Report Posted November 8, 2009 I dont think the comments format ahould make much difference, its just weird that the page only redirects if all the fields are filled in on the form. it sends the email either way, its just the redirection that seems to be a problem. sveral people have looked at it for me and seem to think the code is sound, and that it must be a host issue, preventing it somehow, though i'm not entirely sure why or how! Quote
ashbullmanuk Posted November 8, 2009 Author Report Posted November 8, 2009 Incidently the EOD is a way that allows free text within PHP The PHP heredoc string syntax allows free form text to be used without having to worry about escaping special characters such as quotes and backslashes. The content of the heredoc string is wrapped with << The only rules are that the closing EOD; must be at the beginning of the last line, and the only content on that line, as follows: <?php $myString = << This is some free form text. It can span mutliple lines and can contain otherwise troublesome characters like \ and " and ' without causing any problems. EOD; ?> So this shouldn't be the issue either, and my host have emailed me to say that as the email actually sends, it isn't an issue with them, however a script issue that is causing an error witin the server!!! I feel i have experience in banging my head against a concrete wall!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.