View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Where am I going wrong: GoDaddy won't let my email process form work!

Thread began 4/06/2009 11:49 pm by jojotoronald374823 | Last modified 10/13/2009 10:42 am by jojotoronald374823 | 8090 views | 14 replies

jojotoronald374823

Where am I going wrong: GoDaddy won't let my email process form work!

I've set up a site on GoDaddy. One page of the site is used to process a form with PHP.
The code above Doctype is: (I'm working with Dreamweaver CS4).
When the form is completely filled out and I go to submit it, GoDaddy doesn't allow it to go through (i.e. I get the error message which is embedded in my code.) If I use GoDaddy's form mail (which is also PHP in the action field of the form element (i.e. form ="/gdform.php) it goes through. The code below comes essentially from Dreamweaver CS4 by David Powers. As suggested I have used all 5 fields of the form element. I ask Dave about it, but no answer given helped. GoDaddy isn't very helpful either. Is there something that I am overlooking in the code which the server doesn't like? Any help greatly appreciated! Ron.)


<?php
$tabToShow = 0;

if (array_key_exists('send', $_POST)) {
//mail processing script
// remove escape characters from POST array
if (PHP_VERSION < 6 && get_magic_quotes_gpc()) {
function stripslashes_deep($value) {
$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
}

$to = 'KHPrinters@aol.com'; //use your own email address
$subject = 'Contact information for quote on job';

// list expected fields
$expected = array('name', 'business', 'addressStreet', 'city', 'state', 'zip', 'phone', 'email', 'inquire');
// set required fields
$required = array('name', 'business', 'addressStreet', 'city', 'state', 'zip', 'phone', 'email', 'inquire');
// create empty array for any missing fields
$missing = array();

// assume that there is nothing suspect
$suspect = false;

// create a pattern to locate suspect phrases
$pattern = '/Content-Type:|Bcc:|Cc:/i';

// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}
// check the $_POST array and any subarrays for suspect content
isSuspect($_POST, $pattern, $suspect);
if ($suspect) {
$mailSent = false;
unset($missing);
} else {

// process the $_POST variables
foreach ($_POST as $key => $value) {
// assign to temporary variable and strip whitespace if not an array
$temp = is_array($value) ? $value : trim($value);
// if empty and required, add to $missing array
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
} elseif (in_array($key, $expected)) {
// otherwise, assign to a variable of the same name as $key
${$key} = $temp;
}
}
}
//validate the email address
if (!empty($email)) {// regex to identify illegal characters in email address
$checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
//reject the email address if it doesn't match
if (!preg_match($checkEmail, $email)) {
$suspect = true;
$mailSent = false;
unset($missing);
}

}
// go ahead only if not suspect and all required fields OK
if (!suspect && empty($missing)) {
//build the message
$message = "Name: $name\r\n\r\n";
$message .= "Firm's name: $business\r\n\r\n";
$message .= "Street address: $addressStreet\r\n\r\n";
$message .= "City: $city\r\n\r\n";
$message .= "State: $state\r\n\r\n";
$message .= "Zip code: $zip\r\n\r\n";
$message .= "Phone number: $phone\r\n\r\n";
$message .= "Email address: $email\r\n\r\n";
$message .= "Nature of inquiry: $inquire";

// limit line lenght to 70 characters
$message = wordwrap($message, 70);
//create additional headers
$headers = "From: Kings Highway Printers<khprinters@aol.com>\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
if (!empty($email)) {
$headers .= "\r\nReply-To: $email";
}


// send it
$mailSent = mail($to, $subject, $message, $headers,'-fKHprinters@aol.com');
if ($mailSent) {
// $missing is no longer needed if the email is sent, so unset it
unset($missing);
}
}
else{ // suspect or at least one required field missing
$tabToShow = 4;
}

The PHP code on the form page is:




<div class="TabbedPanelsContent">
<p>If you have any questions or desire any quotes, please completely fill out the form below, and we'll get back to you promptly.</p>
<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>

<p class="warning">Please complete the missing item(s) indicated.</p>
<?php
} elseif ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message. Please try later.</p>
<?php
} elseif ($_POST && $mailSent) {
?>
<p id="greengo"> Your message has been sent. We will contact you soon. </p>
<?php } ?>
<form id="form1" name="form1" method="post" action= "<?php echo $_SERVER['PHP_SELF']; ?>" >
<p>

<label for="name">Name <?php
if (isset($missing) && in_array('name', $missing)) { ?>
<span class="warning">Please enter your name</span><?php } ?>

</label>
<input name="name" type="text" class="backgroundColorInput" id="name" size="35" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name'], ENT_COMPAT, 'UTF-8').'"';
} ?>
/>
<label for="business">Firm's name <?php
if (isset($missing) && in_array('business', $missing)) { ?>
<span class="warning">Please enter your firm's name</span><?php } ?> </label>
<input name="business" type="text" class="backgroundColorInput" id="business" size="35" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['business'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="addressStreet">Street address <?php
if (isset($missing) && in_array('addressStreet', $missing)) { ?>
<span class="warning">Please enter the street address</span><?php } ?> </label>
<input name="addressStreet" type="text" class="backgroundColorInput" id="addressStreet" size="35"<?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['addressStreet'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>

<label for="city">City <?php
if (isset($missing) && in_array('city', $missing)) { ?>
<span class="warning">Please enter your City</span><?php } ?>
</label>
<input name="city" type="text" class="backgroundColorInput" id="city" size="35" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['city'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="state">State <?php
if (isset($missing) && in_array('state', $missing)) { ?>
<span class="warning">Please enter your State </span> <?php } ?> </label>
<input name="state" type="text" class="backgroundColorInput" id="state" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['state'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="zip">Zip code
<?php
if (isset($missing) && in_array('zip', $missing)) { ?>
<span class="warning"> &hellip;and your Zip</span><?php } ?> </label>


<input name="zip" type="text" class="backgroundColorInput" id="zip" size="10" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['zip'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="phone">Phone number <?php
if (isset($missing) && in_array('phone', $missing)) { ?>
<span class="warning">We may need to contact you by phone. </span><?php } ?>
</label>
<input name="phone" type="text" class="backgroundColorInput" id="phone" size="35" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['phone'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="email">Email address <?php
if (isset($missing) && in_array('email', $missing)) { ?>
<span class="warning">We will need to email you some forms.</span><?php } ?> </label>
<input name="email" type="text" class="backgroundColorInput" id="email" size="35" <?php if (isset($missing)) {
echo 'value="' .htmlentities($_POST['email'], ENT_COMPAT, 'UTF-8') .'"';
} ?>

/>
<label for="inquire">Nature of Inquiry<?php
if (isset($missing) && in_array('inquire', $missing)) { ?>
<span class="warning">Let us know what you need in the space below.</span>
<?php } ?></label>
<textarea name="inquire" cols="45" rows="5" class="backgroundColorInput" id="inquire"><?php
if (isset($missing)) {
echo htmlentities($_POST['inquire'], ENT_COMPAT, 'UTF-8'); } ?></textarea>
<label for="send"></label>
<input name="send" type="submit" id="contact" value="Contact us NOW!" />

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...