Jump to content

PHP form to email. are all fields required?


ashbullmanuk

Recommended Posts

Hi, there, I recently posted a topic about my php script not working. That turned out to be a server issue after all - I had to add "ini_set()" and a -f parameter.

However I have now run across another issue. The php script will only divert to the success url, if all the form fields have been entered. If they haven't, the script will still send the email, however it wont divert to the success url. This problem I first noticed when I added the second the form to my website.

This is where it gets a little more confusing. I copied the exact code for the second php processing script, changed the form variables appropriately, changed the email address to post to, and the success page to a different url. Seemed simple enough?

Well it sends the form, but doesn't divert to the success url. I just get that damned 500 - internal error message!

Evan more weirdly (well to me) when I tried to resolve the issue, it prevented the first form from diverting altogether - despite being completely different files, variables and success urls.

So my question is, how does one allow the script to process fully, and divert without needing all the form elements to be filled? And any idea why the second form does not divert at all. I am not sure what the relationship is between the form elements and the scripts ability to divert the to the success page, yet still send the email even without all the form elements being completed!!!!!!

 

Any help is much appreciated!

The script code for the second form is:

<?php

 

/* Subject and Email Variables */

 

$email_to = "conceptarts@kyu-images.com";

$email_subject = "Project Mandate";

$thankyou_url = "http://www.kyu-images.com/contact-us/concept_arts_mandate_form_sent.html";

 

 

/* Gathering Data Variables */

 

$clientnameField = $_POST["clientname"];

$businessnameField = $_POST["businessname"];

$email_from = $_POST["email"];

$phoneField = $_POST["phone"];

$address1Field = $_POST["address1"];

$address2Field = $_POST["address2"];

$townField = $_POST["town"];

$postcodeField = $_POST["postcode"];

$businessField = $_POST["business"];

$productsField = $_POST["products"];

$marketField = $_POST["market"];

$kickstartField = $_POST["kickstart"];

$photographyField = $_POST["photography"];

$termsField = $_POST["terms"];

$webdesignField = $_POST["webdesign"];

$logodesignField = $_POST["logodesign"];

$brandimageField = $_POST["brandimage"];

$mainthemeField = $_POST["maintheme"];

$styles1Field = $_POST["styles1"];

$styles2Field = $_POST["styles2"];

$styles3Field = $_POST["styles3"];

$styles4Field = $_POST["styles14"];

$registerField = $_POST["register"];

$hostingField = $_POST["hosting"];

$pagesField = $_POST["pages"];

$pagenumberField = $_POST["pagenumber"];

$galleryField = $_POST["gallery"];

$gallerynumberField = $_POST["gallerynumber"];

$formsField = $_POST["forms"];

$formnumberField = $_POST["formnumber"];

$filesField = $_POST["files"];

$filenumberField = $_POST["filenumber"];

$regionsField = $_POST["regions"];

$regionnumberField = $_POST["regionnumber"];

$animantionsField = $_POST["animantions"];

$describeField = $_POST["describe"];

$ActivEditingField = $_POST["ActivEditing"];

$databaseField = $_POST["database"];

$detailsField = $_POST["details"];

$usedwhereField = $_POST["usedwhere"];

$addtoField = $_POST["addto"];

$buildonField = $_POST["buildon"];

$purchaseothersField = $_POST["purchaseothers"];

$addprintingField = $_POST["addprinting"];

$graphicsField = $_POST["graphics"];

$dimensionsField = $_POST["dimensions"];

$boxlabeldimensionField = $_POST["boxlabeldimension"];

 

$headers = "From: $email_from . \r\n";

$headers .= "Reply-To: $email_from . \r\n";

$headers .= "Content-type: text/html\r\n";

 

$message = <<

 


 

Client Name: $clientnameField

 

Business Name: $businessnameField

 

Email: $email_from

 

Telephone: $phoneField

 

First Address Line: $address1Field

 

Second Address Line: $address2Field

 

Address Town: $townField

 

Postcode: $postcodeField

 

 


 

About Their Business: $businessField

 

About Their Service/Products: $productsField

 

About Their Target Market: $marketField

 

Package For Kick Start Users: $kickstartField

 

Shoot For Commercial Photography: $photographyField

 

 


 

Terms Agreed: $termsField

 

 


 

Web Design Level: $webdesignField

 

Logo Design Level: $logodesignField

 

Brand Image Level: $brandimageField

 

 


 

Main Design Theme: $mainthemeField

 

Sub Style: $styles1Field

 

Sub Style: $styles2Field

 

Sub Style: $styles3Field

 

Sub Style: $styles4Field

 

 


 

Register Their Site: $registerField

 

Host Their Site: $hostingField

 

Add Pages: $pagesField

 

How Many: $pagenumberField

 

Add Image Galleries: $galleryField

 

How Many: $gallerynumberField

 

Add Online Forms: $formsField

 

How Many: $formnumberField

 

Add Downloadable Files: $filesField

 

How Many: $filenumberField

 

Add Editable Regions: $regionsField

 

How Many: $regionnumberField

 

Add Animations: $animantionsField

 

What Kind: $describeField

 

Subscribe To ActivEditing: $ActivEditingField

 

Create Database: $databaseField

 

List Of Page Contents: $detailsField

 

 


 

Where Will The Logo Be Used: $usedwhereField

 

Add designs to Which Services: $addtoField

 

Build On Existing Designs: $buildonField

 

Purchase other Concept Designs: $purchaseothersField

 

 


 

Additional Printing Requirements: $addprintingField

 

What Graphics For Branding: $graphicsField

 

Flyer, Poster Or Borchure Dimensions And Pages: $dimensionsField

 

Box Or Label Dimensions: $boxlabeldimensionField

 


 

 


 

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

}

 

 

?>

Link to comment
Share on other sites

However I have now run across another issue. The php script will only divert to the success url, if all the form fields have been entered. If they haven't, the script will still send the email, however it wont divert to the success url.

If your form is anything like this one, I don't know why that is happening -- it may be something completely different from filling in the form all the way, because according to your code, none of the fields are required. According to the code, you should be able to send a blank email.

 

Well it sends the form, but doesn't divert to the success url. I just get that damned 500 - internal error message!

This doesn't seem like an issue with the code... That is something to discuss further with your web host. If it was a PHP error, either your'd get a specific PHP error, a blank page (indicating an error, though nothing is sent to the browser) or a 404 error message indicating the file you wanted to send the user to once the form got submitted doesn't exist.

 

I am not sure what the relationship is between the form elements and the scripts ability to divert the to the success page, yet still send the email even without all the form elements being completed!!!!!!

According to the code in your form, there is no relationship between the form elements and diverting to the success page. The only thing the diverting to the success page is relying on is the successful sending of the email. I think this has something to do with the way your PHP mail() function is set up on the host, not anything to do with your code.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...