Current location: Hot Scripts Forums » Programming Languages » PHP » Email form problem


Email form problem

Reply
  #1 (permalink)  
Old 03-07-06, 09:37 AM
slimey slimey is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Email form problem

Hi there all ive been working on this superdooper really easily customizable email form with validation which i have gatherd from a few tutorials i have seen over the net. Then combined them into one big all mighty form. So i can use it at a later date.
Now im not very good with php but i do alright.

The only problem i am have now seeing as i have all my form elements i wanted are these 2 things.

1)Once it has been submitted and is valid it doesnt go to the thank you page even though the code is there.
2)the whole thing wont work at all when i have html in there for the email that is sent so it is formatted a little bit.

I hope someone can help in this matter? Im stuck and id love to have this working.


Thanks in advance
Sean

Here is the email form code

PHP Code:

<?php

// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
    
// Each time there's an error, add an error message to the error array
    // using the field name as the key.
    
if ($_POST['name']=='')
        
$arrErrors['name'] = 'Please provide your name.';
    if (
$_POST['email']=='')
        
$arrErrors['email'] = 'A valid email address is required.';
    if (
$_POST['phone']=='')
        
$arrErrors['phone'] = 'Please provide your phone number.';
    if (
$_POST['inquiry']=='')
        
$arrErrors['inquiry'] = 'Please type you inquiry.';
    if (
count($arrErrors) == 0) {
        
// If the error array is empty, there were no errors.
        // Insert form processing here.
        
        
        
$email        $_POST['email'] ;
$name       stripslashes($_POST['name']) ;
$inquiry     stripslashes($_POST['inquiry']) ;
$business     stripslashes($_POST['business']) ;
$phone         stripslashes($_POST['phone']) ;

$to="ampedwebdesigns@exemail.com.au";
$mailheaders "MIME-Version: 1.0\n";
$mailheaders .= "Content-type: text/html; charset=iso-8859-1\n";
$mailheaders .= "From: $email";
$message="<html><head></head><body><table width='600' style='border: 1px solid #CCCCCC'><tr><td height="264" style='padding: 20px'><font face='arial, sans-serif' size='2'><b style='background-color: #ECECEC; padding: 3px 6px 3px 6px'>$name has sent you an email from the In House Flowers Website.</b><br><br><b>Message:</b> $inquiry<br><br><b>Contact Details:</b><br><br>$name <br>$email<br>$business<br><br><b>Phone Number:</b> $phone</font></td></tr></table></body></html>"
mail$to"In House Flowers - Inquiry"$message$mailheaders);
header"Location: http://home.exetel.com.au/slimey/flowers/www/thank.htm" );
    
    
    
    
    } else {
        
// The error array had something in it. There was an error.
        // Start adding error text to an error string.
        
$strError '<div class="formerror"><p><img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
        
// Get each error and add it to the error string
        // as a list item.
        
foreach ($arrErrors as $error) {
            
$strError .= "<li>$error</li>";
        }
        
$strError .= '</ul></div><p>';
    }
}
?>


<?php echo $strError?>
<form method="post" action="<?php echo $PHP_SELF?>">
<!--
For every form field, we do the following...

Check to see if there's an error message for this form field. If there is,
add the formerror class to the surrounding paragraph block. The formerror
class contains the highlighted box.

Insert the contents of what the user submitted bak into the form field.

Check again to see if this field has an error message. If it does, show
the error icon and the error message next to the field.
-->
<fieldset >
                      <legend class="heading">Inquiry Form </legend>
<p<?php if (!empty($arrErrors['name'])) echo ' class="formerror"'?>>
    <label for="name" class="content">Name:</label><br>
    <input name="name" type="text" id="name" value="<?php echo $_POST['name'?>">
    <?php if (!empty($arrErrors['name'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['name'].'</span>'?>
</p>
<p<?php if (!empty($arrErrors['phone'])) echo ' class="formerror"'?>>
    <label for="phone" class="content">Phone:</label><br>
    <input name="phone" type="text" id="phone" value="<?php echo $_POST['phone'?>">
    <?php if (!empty($arrErrors['phone'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['phone'].'</span>'?>
</p>
<p><label for="business" class="content">Business Name: (If Applicable)</label><br>
                      <input name="business" type="text" id="business" size="35">
<p<?php if (!empty($arrErrors['email'])) echo ' class="formerror"'?>>
    <label for="email" class="content">Email:</label><br>
    <input name="email" type="text" id="email" value="<?php echo $_POST['email'?>">
    <?php if (!empty($arrErrors['email'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['email'].'</span>'?>
</p>
<p<?php if (!empty($arrErrors['inquiry'])) echo ' class="formerror"'?>>
    <label for="inquiry" class="content">Inquiry details:</label><br>
    <textarea name="inquiry" cols="35" rows="5" id="inquiry" value="<?php echo $_POST['inquiry'?>"></textarea>
    <?php if (!empty($arrErrors['inquiry'])) echo '<img src="images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br /><span class="errortext">'.$arrErrors['inquiry'].'</span>'?>
</p>

<p>
    <input type="submit" name="Submit" value="Submit">
</p></fieldset>
</form>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-08-06, 03:46 AM
slimey slimey is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Looks like i found the problem I had to escape to quotes. ie

PHP Code:

$message="<html><head></head><body><table width='600' style='border: 1px solid #CCCCCC'><tr><td height="264" style='padding... 

should be
...height=\"264\" style...

works perfect now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP email form problem jcwilde1 PHP 2 06-19-05 12:19 AM
Need Help in Email Registration Form jamal Script Requests 0 06-06-05 03:13 AM
form to anyone's email with Image Verification ghostrider632 PHP 1 05-11-05 10:08 AM


All times are GMT -5. The time now is 10:03 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.