logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-09-2012, 07:11 AM   #1
vapidrob
 
Join Date: Mar 2012
Posts: 3
Default Trying to build a simple contact email form

Hi all. I'm trying to build a simple contact form but cant figure out how to get the Email sent to me to show who its from in the "From" when it goes to the inbox. Here is the HTML and PHP code:

HTML:
Code:
<html>
<head></head>
<body>

<form action="mail.php" method="POST">
<div>

<p>Name</p>
<input name="name" type="text"> <br> </div>
<div>

<p>E-Mail</p>
<input name="email" type="text"> <br> </div>
<div>

<p>Telephone</p>
<input name="telephone" type="text"> <br> </div>

<p>Comment</p>
<textarea cols="30" name="comment" rows="9"></textarea>
<br> </div>

<div>
<input name="submit" type="submit" value="Send"> </div>

</form>
 
</body>
 
</html>
and the mail.php code:
Code:
<?php
if(isset($_POST['submit'])) {
$to = "me@me.com";
$subject = "Email from webform";
 
// data from visitor
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$telephone = filter_var($_POST['telephone'], FILTER_SANITIZE_STRING);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
 
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Telephone: $telephone\n\n  Message:\n\n $comment";
 
mail($to, $subject, $body);
 
// redirect to confirmation
header('Location: confirmation.htm');
} else {
// handle the error somehow
}
?>
and Confirmation Thank you for submitting page code:
Code:
<html>
<head></head>
 <body>
<h1>&nbsp;</h1>
<h1>Thank You!</h1>
<p>We've received your feedback and will get back soon.</p>
 
</body>
 
</html>
What am I missing, because when I send a test email, it sends all the proper form elements, but from the top of the email headers, the "From" who it was, I always get "Nobody@nobody.com

I just want to be able to put the correct "From" in the email header.

What am I missing with this code?

Thank you for your help in advance!
vapidrob is offline   Reply With Quote
Old 03-19-2012, 12:57 PM   #2
domedia
Administrator
domedia's Avatar
 
Join Date: Dec 2003
Posts: 9,730
Default

vapidrob, you're not setting the from field anywhere.
domedia is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 05:29 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com