Jump to content

contact php file for web


jiminfo

Recommended Posts

Hi Peeps, I have tried but am trying to get a website up and working and am stumbling with the php side of things. Please help.

 

html

 

<form id="contacts-form" name="contacts-form" action="contact1.php" method="post" >
                            <fieldset>
                              <div class="field">
                                <label>Your Name:</label>
                                <input type="text" class="input" name="name" id="name">
                               </div>
                              <div class="field">
                                <label>Your E-mail:</label>
                                <input type="text" class="input" name="email" id="email">
                               </div>
                              <div class="field">
                                <label>Your Website:</label>
                                <input type="text" class="input" name="website" id="website">
                               </div>
                              <div class="field">
                                <label>Your Message:</label>
                                <textarea name="textarea" id="textarea" cols="" rows=""></textarea>
                               </div>
                              <div class="alignright"><a href="contact-us.html" onclick="document.getElementById('contacts-form').submit()"><strong>Send Your Message!</strong></a></div>
                           </fieldset>
                         </form>

 

php is..

<?php
   $name    = $_POST ['name'];
   $website = $_POST ['website'];
   $email   = $_POST ['email'];
   $message = $_POST ['textarea'];
   if(!$name || !$website || !$email || !$textarea)
<form method='post' action='contact1.php'>
   Name: <br /><input name='name' type='text' value='$name' /><br /><br />
   Company: <br /><input name='website' type='text' value='$website' /><br /><br />
   EMail: <br /><input name='email' type='text' value='$email' /><br /><br />
   Message:<br />
   <textarea name='textarea' cols='55' rows='8'>$textarea</textarea><br /><br />
   <input type='submit' value='Send' />
</form>
<p>All fields are required</p>
$send_to = "[email protected]"; // change to your email
mail($send_to, "Name: $name: $website" , $textarea, "From: $email");
echo "Thank you for your feedback";
?>

 

form just resets and does not send a mail. I really hope you can help.

 

J

Link to comment
https://forums.phpfreaks.com/topic/291534-contact-php-file-for-web/
Share on other sites

Do you use a php editor ? You should see at once that you miss a php close tag. or is it because bad copy and paste work to this board?

 

start all over like this:

<?php

$firstname = '';
$error = NULL;

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $firstname = $_POST['firstname'];

    //validation
    if(strlen($firstname) < 2)
        $error = 'Please fill in your firstname!';

    if(!$error)
    {
        // do some actions like sending an email
		
		// redirect
        header('Location thankyou.html');
    }
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My first Form</title>
</head>

<body>
<p><?php echo $error; ?></p>
<form action="" method="post">
	<input type="text" name="firstname" value="<?php echo $firstname; ?>" />
    <button type="submit">Send</button>
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.