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

Thread Tools Display Modes
Old 03-09-2012, 07:11 AM   #1
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:


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

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

<input name="email" type="text"> <br> </div>

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

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

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

and the mail.php code:
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:
<h1>Thank You!</h1>
<p>We've received your feedback and will get back soon.</p>
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's Avatar
Join Date: Dec 2003
Posts: 9,730

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

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 01:30 PM.

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