Hi guys,

Here is my php code. what i am trying to do is send an order email with either plain text or with my logo. The form seems to work no prob but only for the form validation at seems to keep getting me stuck. I've been going around in circles trying to understand this is not work. I seem to only have one hair left on my head now, after they were all pulled out trying to sort this. Can you please help. Code is:
PHP Code:
<?php require_once('recaptchalib.php');
$privatekey "***";
$resp recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
            if( isset(
$_POST['submit'])) {
                if (
$resp->is_valid) {      
            
?>
            <?php if ($_POST) { // CURLY BRACKET (Open): After Clicking Submit
                
foreach ($_POST as $field => $value) {
                            
$value trim($value);
                }
// Creating Variables
// Creating Email Variables
$to "***";
$inquiry $_POST['inquiry'];
$first_name $_POST['first_name'];
$email $_POST['email'];
$getcopy $_POST['getcopy'];
$headers $_POST['email'];
$header2="From: " $email "\r\n" .
"Customer Order: " $_POST['inquiry'] . "\r\n" .
"First Name: " $_POST['first_name'] . "\r\n" .
"E-mail: " $_POST['email'];
$random_hash md5(date('r'time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers "From: \r\nReply-To: ";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

// Creating Add-On Variables
$username $_POST['username'];
$password $_POST['password'];
$domain $_POST['domain'];
$domprefix $_POST['domprefix'];
// Creating cPanel main account Variables
// cPanel username
$cpanel_user "***";
// cPanel password
$cpanel_password "***";
// cPanel host
$cpanel_host "***";
// cPanel theme/skin, usually "x"
$cpanel_skin "x3";
// Path to cURL on your server
$curl_path "/usr/bin/curl";

// Set Up The Customer's Web Hosting Account
$database exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adddb.html?db=$username'");
$adduser exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adduser.html?user=$username&pass=$password'");
$asignuser exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/addusertodb.html?user=$cpanel_user_$username&db=$cpanel_user_$username&ALL=ALL'");
$dom exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/addon/doadddomain.html?domain=$domain.$domprefix&user=$domain&pass=$password'");
$ftp exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/ftp/doaddftp.html?login=$username&password=$password&homedir=$subdomain&quota=500'");
$popmail exec("$curl_path 'http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/mail/doaddpop.html?email=$username&domain=$subdomain.your primary domain&password=$password&quota=20'");

//define the body of the message.
ob_start(); //Turn on output buffering
?>

--PHP-mixed-<?php echo $random_hash?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash?>"

--PHP-alt-<?php echo $random_hash?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Dear <?php echo $_POST['first_name'];?>,
If you haven't already paid for the order, please now pay:

--PHP-alt-<?php echo $random_hash?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<body style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff; color:#ffffff; margin:0; padding:0">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" style="border-left: ridge #60EA23 1px; border-right: ridge #C20201 1px">
    <tr>
        <td style="padding-left:40px; padding-right:40px; color:#6f746c; font-size:12px">
<h2>Dear <?php echo $_POST['first_name'];?>,</h2>
<p>If you haven't already paid for the order, please now pay:</p><br>
<br>
</td>
    </tr>
    <tr>
        <td style="background:#BE0201; font-size:1px; height:10px">&nbsp;</td>
    </tr>
</table>

--PHP-alt-<?php echo $random_hash?>--

--PHP-mixed-<?php echo $random_hash?>--
<?php

// Create empty ERROR variables
$error ""// for fields left BLANK
$errorflag ""// for fields with INVALID data entered

// Check for field/fields that is/are left BLANK
if (($first_name == "") || ($email == "")) { // CURLY BRACKET (Open): For Validating if fields are left blank
$error "<p><span class='colorTextBlue'>Please fill in all fields!</span></p>";
// CURLY BRACKET (Close): For Validating if fields are left blank

else { // CURLY BRACKET (Open): Form Validation
// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
if (ctype_alpha($first_name) == FALSE) {
$error "<p><span class='colorTextBlue'>Please enter a valid First Name <span class='italic'>(Alphabets only)</span></span></p>";
$errorflag="first_name";
}
// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if ((strpos($email"@") == FALSE) || (strpos($email".") == FALSE) || (strpos($email" ") != FALSE)) {
$error "<p><span class='colorTextBlue'>Please enter a valid E-mail</span></p>";
$errorflag="email";
}
// CURLY BRACKET (Close): Form Validation

// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
// If there's an error along with displaying the list of flagged error/errors
if ($error != "") { // CURLY BRACKET (Open): For Error
echo "<p><b><span class='colorTextRed'>Error Occured: </b>" $error."</span></p>" ;
// CURLY BRACKET (Close): For Error


// If there's NO error at all, along with displaying the filled fields
else if (mail($to$inquiry$header2))
{
echo 
"<p><span class='colorTextBlue'>Order Settings:</span></p><br/>";
echo 
"<p>Following are the details of your order.<br/> Please use the <b>Buy Now</b> button to buy:<br/><br/></p>";
echo 
"<table border=\"0\" width=\"98%\" cellpadding=\"4\" cellspacing=\"1\" class=\"table_layout\">";
echo 
"<tbody>";
echo 
"<tr>";
echo 
"<th width=\"35%\"><b>Order Details:</b></th>";
echo 
"<td width=\"65%\">" $inquiry "</td>";
echo 
"</tr>";
echo 
"<tr>";
echo 
"<th width=\"35%\"><b>E-mail:</b></th>";
echo 
"<td width=\"65%\">" $email "</td>";
echo 
"</tr>";
echo 
"</tbody>";
echo 
"</table>";



else {
$error "<p><span class='colorTextRed'>&nbsp;&nbsp;&nbsp;There was an error in your order. Please go back and fix this error.</span></p>";
}
if (
$getcopy=="1") {
    
$message ob_get_clean();
    
mail($email$inquiry$message$headers);
    echo 
"<p><span class='colorTextBlue'>Order Settings:</span></p><br/>";
    echo 
"<p>Following are the details of your order.<br/> Please use the <b>Buy Now</b> button to buy:<br/><br/></p>";
    echo 
"<table border=\"0\" width=\"98%\" cellpadding=\"4\" cellspacing=\"1\" class=\"table_layout\">";
    echo 
"<tbody>";
    echo 
"<tr>";
    echo 
"<th width=\"35%\"><b>Order Details:</b></th>";
    echo 
"<td width=\"65%\">" $inquiry "</td>";
    echo 
"</tr>";
    echo 
"<tr>";
    echo 
"<th width=\"35%\"><b>E-mail:</b></th>";
    echo 
"<td width=\"65%\">" $email "</td>";
    echo 
"</tr>";
    echo 
"</tbody>";
    echo 
"</table>";
}
// CURLY BRACKET (Close): After Clicking Submit

// Displays the Empty variables i.e. when the Contact Form appears completely blank for the VERY FIRST time with all blank fields
else {
    
$inquiry "";
$first_name "";
$email "";
$errorflag "";
}
} else {
        if (!
$resp->is_valid) {
  die (
"<p>The Security Code wasn't entered correctly. Please go back and try it again. " "(Security Code: " $resp->error ")");
   }
}}
?>