Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

Contact me form error

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Contact me form error

Postby waidinho » Thu Mar 28, 2013 6:22 am

I have following form:
Code: Select all
<form id="form" class="blocks" action="email.php" method="post">
      <p>
         <label>Name: <font style="color:red">*</font></label>
         <input type="text" class="text" name="name"/>
      </p>
      <p>
         <label>e-mail <font style="color:red">*</font></label>
         <input type="text" class="text" name="email"/>
      </p>
      <p>
         <label>Phone: </label>
         <input type="text" class="text" name="phone"/>
      </p>
      <p>
         <label>Subject: <font style="color:red">*</font></label>
         <input type="text" class="text" name="theme" />
      </p>
      <p class="area">
         <label>Message: <font style="color:red">*</font></label>
         <textarea class="textarea" name="message"></textarea>
      </p>
      <p>
         <label>&nbsp;</label>
         <input type="submit" class="btn" value="Siųsti laišką" />
      </p>
   </form>

When i fill in form and send email to my gmail acc, in my gmail it shows me that email sender is "unknown". How to make it show correctly $name? My php code is below:
Code: Select all
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$email_subject = "$subject";
$email_body = "         name: $name.\n
            e-mail: $email.\n
            phone: $phone.\n
            subject: $subject.\n
            message: $message.\n";
   
$to = "myemail@gmail.com";
$headers = "From: $name \r\n";
$headers .= "Reply-To: $email \r\n";

mail($to,$email_subject,$email_body,$headers);
header('Location: email-sent.php');   
?>
waidinho
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Mar 28, 2013 6:15 am

Re: Contact me form error

Postby egami » Fri Mar 29, 2013 8:08 am

make sure that $_POST['name'] is actually defined and is a valid email format.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.