Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Form, PHP and sendmail issues.

New Here ,
Nov 05, 2009 Nov 05, 2009

Hi, I am new to web design, and am trying to set up a web site for a study project.  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!

TOPICS
Server side applications
673
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 08, 2009 Nov 08, 2009

use javascript or php validation or both.  google php form validation, or use the built in spry validation tools.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 08, 2009 Nov 08, 2009

Thanks for your reply,

Do you think this will enable the form to divert to the success url even if the user hasn't entered data into all the fields, If I validate say one or two?

Many Thanks

Ash Bullman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 08, 2009 Nov 08, 2009

yes

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 08, 2009 Nov 08, 2009

Hi again,

I tried adding validation in, but its the same, if all form fields are filled in, then it goes to the success url, if 1 or more boxes left empty, it just gets a 500 internal server error.

Many Thanks

Ash Bullman

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 10, 2009 Nov 10, 2009

Please post your code.  It's hard to tell what's going on but it may be a simple fix.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2009 Nov 11, 2009
LATEST

Hi,

The code 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 = <<<EOD <br><hr><br> Name: $nameField <br> Email: $email_from <br> First Address Line: $address1Field <br> Second Address Line: $address2Field <br> Address Town: $townField <br> Postcode: $postcodeField <br> Telephone: $phoneField <br> Service Enquiry: $serviceField <br> Send Brochure: $brochureField <br> How Did They Find Us: $aboutusField <br> Did They Like Our Site: $oursiteField <br> Client Comments: $commentsField <br> <br><hr><br>

EOD;

ini_set("sendmail_from", $email_from);

$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);

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.";

}

?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines