Topic: PHP form to email. are all fields required?

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/co … _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 = <<<EOD
<br><hr><br>
Client Name: $clientnameField <br>
Business Name: $businessnameField <br>
Email: $email_from <br>
Telephone: $phoneField <br>
First Address Line: $address1Field <br>
Second Address Line: $address2Field <br>
Address Town: $townField <br>
Postcode: $postcodeField <br>
<br><hr><br>
About Their Business: $businessField <br>
About Their Service/Products: $productsField <br>
About Their Target Market: $marketField <br>
Package For Kick Start Users: $kickstartField <br>
Shoot For Commercial Photography: $photographyField <br>
<br><hr><br>
Terms Agreed: $termsField <br>
<br><hr><br>
Web Design Level: $webdesignField <br>
Logo Design Level: $logodesignField <br>
Brand Image Level: $brandimageField <br>
<br><hr><br>
Main Design Theme: $mainthemeField <br>
Sub Style: $styles1Field <br>
Sub Style: $styles2Field <br>
Sub Style: $styles3Field <br>
Sub Style: $styles4Field <br>
<br><hr><br>
Register Their Site: $registerField <br>
Host Their Site: $hostingField <br>
Add Pages: $pagesField <br>
How Many: $pagenumberField <br>
Add Image Galleries: $galleryField <br>
How Many: $gallerynumberField <br>
Add Online Forms: $formsField <br>
How Many: $formnumberField <br>
Add Downloadable Files: $filesField <br>
How Many: $filenumberField <br>
Add Editable Regions: $regionsField <br>
How Many: $regionnumberField <br>
Add Animations: $animantionsField <br>
What Kind: $describeField <br>
Subscribe To ActivEditing: $ActivEditingField <br>
Create Database: $databaseField <br>
List Of Page Contents: $detailsField <br>
<br><hr><br>
Where Will The Logo Be Used: $usedwhereField <br>
Add designs to Which Services: $addtoField <br>
Build On Existing Designs: $buildonField <br>
Purchase other Concept Designs: $purchaseothersField <br>
<br><hr><br>
Additional Printing Requirements: $addprintingField <br>
What Graphics For Branding: $graphicsField <br>
Flyer, Poster Or Borchure Dimensions And Pages: $dimensionsField <br>
Box Or Label Dimensions: $boxlabeldimensionField <Br>
<br><hr><br>
<br><hr><br>
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.";
    }


?>

Re: PHP form to email. are all fields required?

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.

Re: PHP form to email. are all fields required?

Thank you for your advice Mr Falk, Seem like still more hosting issues then. I will post how it goes with them!