[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum

This is a discussion on "[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum" within the PHP Forum section. This forum, and the thread "[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 12th, 2007, 11:55
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 227
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum

I have just finished the Email Form Submit tutorial located in the top of the Php forum next to Rakuli's Tutorial. I have uploaded the email submit form to a server and were the person is meant to be filling in the textfields in the form and so on i can see the code from the form itself inside the textfields, at first i thought the problem was the way i had copied the code, but the creator of the tutorial sent me the Php file and its still the same. So just imagine you wanted to fill in your name in the name section of the form i carnt because the text field itself is filled with the code.

Here's the origanal code from the origanal Php file.

Is there anyone who can help me with a email form submit script, i have tried countless sites on the net and they all seem a little faulty hear and there.

If anyone has a fix 4 the code below it would be great.

PHP: Select all

<?php
/****** PHP Form Mail *****/
// declare and initialize some variables
$name=$email=$subject=$message=$error_message='';
$invalid_fields=array();
$required_fields=array('name','email','message');
$validated=array();
$to_address='blub@bla.com'// your email address goes here
// validate $_POST array
if(count($_POST)>0) { // was something posted?
 
foreach($_POST as $key=>$value) { // loop through the $_POST array
  
if(in_array($key,$required_fields)&&$value=='') { // check if a required field is empty
    // add that field to the $invalid_fields array
   
array_push($invalid_fields,$key);
   
// and append the error message to the $error_message variable
   
$error_message.='<p>Please enter a'.(preg_match('/^[aeiouy]/',$key)?'n':'').' '.$key.'.</p>';
  } else {
   switch(
$key) {
    case 
'email'// validate email address format
     
if(!preg_match('/^([A-Z0-9._%-]+)@([A-Z0-9.-]+)\.([A-Z]{2,6})$/i',$value)) {
      
array_push($invalid_fields,'email');
      
$error_message.='<p>Please enter a valid email.</p>';
     }
     break;
   }
  }
  
// field is not in the $invalid_fields array?
  
if(!in_array($key,$invalid_fields)) {
   
// copy it to the $validated array
   
$validated[$key]=htmlspecialchars($value);
  }
 }
} else { 
// make everything invalid so that the form is outputted and not the thankyou message
 
$invalid_fields=$required_fields;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtmlxml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>form mail</title>
<style type="text/css" media="all">
* { margin:0;padding:0; }
body { font:600 12px/22px verdana;padding:50px; }
.box, textarea, .button { border:2px solid #6699CC;font:inherit;color:inherit; }
.box { width:250px; }
textarea { width:300px;height:250px; }
.error { color:#DD1100; }
</style>
</head>
<body>
<div class="contact">
 <h1>Contact Us</h1>
<?php
if(count($invalid_fields)<=0) { // send message / thank user
 
$formatted_message='When: '.date('r').'
Who: '
.$name.' ('.$email.')
With What: '
.$_SERVER['HTTP_USER_AGENT'].'
Message: '
.$message;
 
//mail($to_address,$subject,$formatted_message);
 
echo($formatted_message);
?>
 <p>Your message was successfully delivered.</p>
<?php } else { ?>
 <p>Please fill out the form to contact us. Required fields are marked with a star [*].</p>
 <?php echo(($error_message!=''?'<div class="error">'.$error_message.'</div>':'')); ?>
 <form name="contact" action="form_mail.php" method="post">
  <p>Name:* <input class="box" type="text" name="name" value="<?php echo($validated['name']); ?>" /></p>
  <p>E-Mail:* <input class="box" type="text" name="email" value="<?php echo($validated['email']); ?>" /></p>
  <p>Subject: <input class="box" type="text" name="subject" value="<?php echo($validated['subject']); ?>" /></p>
  <p>Message:*</p><textarea name="message"><?php echo($validated['message']); ?></textarea>
  <p><input class="button" type="submit" action="submit" value="Send" />
 </form>
<?php ?>
</div>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 12th, 2007, 12:13
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Email Submit Form Problem, The tutorial From The Php Forum

This is a contact form I use
It redirects to itself and if the mail is sent, it displays a confirmation message.
Also the form is checked for validation and displays any errors

PHP: Select all

<?php
// Change to your own email address
$your_email "you@yourdomain.com";

// This is what is displayed in the email subject line
// Change it if you want
$subject "Message via your contact form";

// This is displayed when the email has been sent
$thankyou_message "<p>Thankyou. Your message has been sent.</p>";

$self $_SERVER['REQUEST_URI'];

$name $_POST['txtName'];
$email $_POST['txtEmail'];
$message $_POST['txtMessage'];
$send $_POST['send'];

$msg="<p>Please fill in this form if you have any queries or suggestions.</p>";

echo (
$msg);

$form "
    <form method=\"post\" action=\"$self\">

    <p><label for=\"txtName\">Name:</label>
    <input type=\"text\" title=\"Please enter your name\" id=\"txtName\" name=\"txtName\" size=\"40\" value=\"$name\" /></p>

    <p><label for=\"txtEmail\">Email:</label>
    <input type=\"text\" title=\"Please enter your email address\" id=\"txtEmail\" name=\"txtEmail\" size=\"40\" value=\"$email\"/></p>

    <p><label for=\"txtMessage\">Comments:</label>
    <textarea title=\"Please enter your message\" id=\"txtMessage\" name=\"txtMessage\" rows=\"20\" cols=\"45\">$message</textarea></p>

        <p><label>&nbsp;</label>
    <input type=\"submit\" class=\"sendbutton\" name=\"send\" value=\"Submit\" /></p>

</form>"
;

if(
$send)
{
    
$valid=true;

    if( !
$name )
    { 
        
$errmsg.="Please enter your name:<br />";
        
$valid=false;
    }

    if( !
$email )
    {
        
$errmsg.="Please enter your email address:<br />";
        
$valid=false;
    }
    else
    {
        
$email trim($email);
        
$_name "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+";
        
$_host "([-0-9A-Z]+\.)+";
        
$_tlds "([0-9A-Z]){2,4}$/i";
            
        if( !
preg_match($_name."@".$_host.$_tlds,$email))
        {
            
$errmsg.="Email address has incorrect format!<br />";
            
$valid=false;
        }
    }
    
    if( !
$message )
    { 
        
$errmsg.="Please enter your message:<br />";
        
$valid=false
    }

if( 
$valid !=true )
    {
    echo( 
"<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" $form );
    }

else {

    
// Stop the form being used from an external URL
    // Get the referring URL
    
$referer $_SERVER['HTTP_REFERER'];
    
// Get the URL of this page
    
$this_url "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
    
// If the referring URL and the URL of this page don't match then
    // display a message and don't send the email.
    
if ($referer != $this_url) {
        echo 
"You do not have permission to use this script from another URL.<br />";
    echo 
"If you are behind a firewall please check your referrer settings.";
        exit;
    }

    
// The URLs matched so send the email
    
if( mail($your_email$subject$message"From: $name <$email>"));
    {
        
// Display the thankyou message
        
echo $thankyou_message;
    }
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 12th, 2007, 12:33
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 227
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Email Submit Form Problem, The tutorial From The Php Forum

Ah Thank You Very Much M8t!

Am just going to give it a try now
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 12th, 2007, 20:06
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [SOLVED] Email Submit Form Problem, The tutorial From The Php Forum

I just put that in the content div of my web page and used css to style the form
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Form Submit To Email longstand PHP Forum 17 Nov 13th, 2007 13:16
[SOLVED] large radio button form submit chriscant JavaScript Forum 7 Oct 25th, 2007 09:03
PHP form to email tutorial cullinanweb PHP Forum 6 Jul 15th, 2007 17:40
Submit Form through EMAIL brunette JavaScript Forum 1 Aug 30th, 2006 19:57


All times are GMT. The time now is 14:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42