-1

I'm thinking this is an easy fix for someone who's familiar with PHP. I've been searching for an answer for 2 days. While great information, none is solving. See the 3rd section below – I receive the form less the field info. What am I doing wrong?

Note that the form itself is wrapped in <html><body><section> tags which don’t appear below.

This is the form:

<form name="Seller" id="restaurant-fm" action="send2.php"  method="POST" enctype="text/plain">  
<input type="text" name="name" required="required" id="name" size="25"       
 value="" placeholder="Your name" autocomplete="on" tabindex="1"          

class="txtinput">
<input type="email" name="email" required="required" id="email" size="25" value="" placeholder="Your e-mail address" autocomplete="on" tabindex="2"        
class="txtinput">       
<input type="tel" name="phone" id="phone" placeholder="Your phone number" tabindex="3" size="12" value="" class="txtinput">
<textarea name="message" id="inquiry" placeholder="(Optional) Enter message here..." tabindex="4" class="txtblock"></textarea> 

<section id="buttons">
<input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="6" value="CLICK TO GET STARTED">
<br style="clear:both;">
</section>
</form>

2) This is the PHP send script I’m using:

<?PHP
$name= $_POST['name1'];
$email= $_POST['email'];
$phone= $_POST['phone'];
$subject = $_POST["subject"];
$inquiry= $_POST['message'];
$to ="myname@mydomain.com";
$subject= "New Contact";
$message= "A visitor sent you the following information: \n\nname:$name; \n\nemail:$email; \n\nphone:$phone; \n\nmessage:$message; \n\nPlease respond to this inquiry immediately";
$headers = "From: $email";
{mail($to,$subject,$message);
header("Location:/About.html");}
?>

3) Here’s what I receive from the form:

A visitor sent you the following information: 

name:; 

email:; 

phone:; 

message:; 
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Scott P
  • 23
  • 3

2 Answers2

2

Firstly, you need to remove enctype="text/plain" from your form tags.

Read the following Q&A on Stack about it; it's more descriptive:

Then you're using <input type="text" name="name"... and using name as the name attribute, yet you using name1 for the POST array $_POST['name1'].

You also have a bunch of semi-colons in your $message= "A visitor.... which are end of statement characters; remove them.

Then you have the following which isn't included in your mail() function, therefore the from never happens.

$headers = "From: $email";

and you also need to add the $headers variable to mail($to,$subject,$message);

mail($to,$subject,$message,$headers);

You also need to remove the braces from:

{mail($to,$subject,$message);
header("Location:/About.html");}

Those are mostly used in conditional statements, which you probably meant to use.

I.e.:

if(mail($to,$subject,$message,$headers)){
    header("Location:/About.html");
    exit;
    }

else{
    echo "Mail failed. Check your logs";
    }

Sidenote: It's always best to add exit; after a header. Otherwise and if you have more code following it, your code may want to continue to execute.

mail($to,$subject,$message);
    header("Location:/About.html");
    exit;

Having used error reporting, would have signaled quite a few notices.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.


Final notes.

It's best to check against your inputs for emptyness.

I.e.: if(!empty($var)){...}

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0

You could try removing value="" Also remove all semicolons after the variables in your message string e.g. change $name; to just $name

Make sure your name field is called the same as the POST variable you are collecting (currently name seems to be being sent but the script is looking for name1).

Can you echo the variables from your script as they arrive?

On most servers you will need to make the "from" a domain on your server and add a "replyto" for the email address from the form. Remember to clean up your input data to avoid script attack.

Steve
  • 808
  • 1
  • 9
  • 14
  • Please do not use answers to ask clarification questions. [It's not hard to earn enough rep to make comments.](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead) – Jay Blanchard Nov 05 '15 at 18:14
  • your edits are getting closer, but you missed something. A few actually. – Funk Forty Niner Nov 05 '15 at 18:18