Jump to content

PHP with HTML Contact Form


music_fan01

Recommended Posts

When I put my contact form into my html and save it as php, nothing happens and I get no error messages.  :( I am not too sure if I placed my php in the wrong place.

 


<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email 

address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Test'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
                echo "Thank you for your email!<br/><br/>";  
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author 

intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
      
    <form name="form1" method="post" action="contact.php">  
    Name: <br/>  
    <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" 

/><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> 

<br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>  
    <br/>  
    <input type="submit" name="Submit" onSubmit="return form1()"/>  
    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality 

Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>










Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.