Jump to content

Simple PHP/HTML contact form giving me trouble. Any advice?


Badwolf

Recommended Posts

(php is a weakness)

 

 

Here is the HTML portion for the form:

 

 

<form action="send_form_email.php" id="contacts-form" method="post">
<fieldset>
<div class="grid3 first">
<label>Name:<br />
<input type="text" name="name" value="" id="name" />
</label>
<label>E-mail:<br />
<input type="email" value="" name ="email" id="email" />
</label>
</div>
<div class="grid3">Message:<br />
<textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea>
<div class="alignleft">
<a href="#" class="alt" onClick="document.getElementById('contacts-form').reset()">Clear</a>      <a href="#" class="alt" onClick="document.getElementById('contacts-form').submit()">Submit</a>
</div>
</div>
</fieldset>
</form>
 
 
 
 
 
 
Here is the PHP portion
 
 
<?php 
$ToEmail = '[email protected]'; 
$EmailSubject = 'Site contact form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"].""; 
$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

 

 

 

 

 

<3

  • 4 weeks later...
  • 3 weeks later...

Here you go:

<!DOCTYPE html>
<html lang="en">
<head></head>
<body>

<form action="send_form_email.php" id="contacts-form" method="post">
<fieldset>
<div class="grid3 first">
<label>Name:<br/>
<input type="text" name="name" value="" id="name" />
</label>
<br/><label>E-mail:<br/>
<input type="email" value="" name ="email" id="email" />
</label>
</div>
<div class="grid3">Message:<br/>
<textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea>
<div class="alignleft">
<a href="#" class="alt" onClick="document.getElementById('contacts-form').reset()">Clear</a>      <a href="#" class="alt" onClick="document.getElementById('contacts-form').submit()">Submit</a>
</div>
</div>
</fieldset>
</form>

</body>

<?php 
if(isset($_POST['submit'])){
    $to = "[email protected]"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $subject = 'Site contact form'; 
   
    $message = "Name: ".$_POST["name"]."" . "Email: ".$_POST["email"]."" ."Comment: ".nl2br($_POST["comment"])."";
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent. Thank you " . 
?>
</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.