Jump to content

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


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 = 'abcdefg12345@gmail.com'; 
$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@example.com"; // 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>
Edited by jeffreyappel
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.