0

I use Dreamweaver CS6 and the php code that I'm using sends the form to my email, but not the data from who fills it out. My code on my php is (actual email is replaced with "email@email.com":

    <?php
$to= "email@email.com";
$subject= "Endorsement Form";
$message= "Endorser name: " . $_POST['name'] . "\r\n" . 
"Email:             " . $_POST['email'] . "\r\n" . 
"Address:           " . $_POST['address'] . "\r\n" . 
"City:              " . $_POST['city'] . "\r\n" . 
"State:             " . $_POST['state'] . "\r\n" . 
"Zip Code:          " . $_POST['zipcode'] . "\r\n" . 
"Phone Number:      " . $_POST['phonenumber'] . "\r\n" . 
"Endorsement Type   " . $_POST['endorsementtype'] . "\r\n" . "\r\n" . 
"Endorsement Quote  " . $_POST['endorsementquote'] . "\r\n" ."\r\n" .
$from= $_POST['email'];
$headers= "From: $from" . "\r\n";
$headers .= "Bcc: email@email.com" . "\r\n";
mail($to,$subject,$message,$headers);  
?>

And my HTML form:

    <form id="endorsementForm" name="endorsementForm" method="post"     action="email_form.php" enctype="text/plain">
        <span id="sprytextfield1">
          <label for="name">Name:</label>
          <br />
          <input type="text" name="name" id="name" />
          <span class="textfieldRequiredMsg">*</span></span>
            <p><span id="sprytextfield2">
          <label for="email">Email:<br />
          </label>
          <input type="text" name="email" id="email" />
          <span class="textfieldRequiredMsg">*</span><span     class="textfieldInvalidFormatMsg">*</span></span></p>
        <p><span id="sprytextfield3">
          <label for="address">Address:</label>
          <br />
          <input type="text" name="address" id="address" />
          <span class="textfieldRequiredMsg">*</span></span></p>
        <p><span id="sprytextfield4">
          <label for="city">City:</label>
          <br />
          <input type="text" name="city" id="city" />
          <span class="textfieldRequiredMsg">*</span></span></p>
        <p><span id="sprytextfield5">
          <label for="state">State:<br />
          </label>
          <input type="text" name="state" id="state" />
          <span class="textfieldRequiredMsg">*</span></span></p>
        <p><span id="sprytextfield6">
          <label for="zipcode">Zip Code:<br />
          </label>
          <input type="text" name="zipcode" id="zipcode" />
          <span class="textfieldRequiredMsg">*</span><span     class="textfieldInvalidFormatMsg">*</span></span></p>
        <p><span id="sprytextfield7">
          <label for="phonenumber">Phone Number:</label>
          <br />
          <input type="text" name="phonenumber" id="phonenumber" />
          <span class="textfieldRequiredMsg">*</span></span></p>
        <p>Endorsment Type:</p>
        <p><span id="spryradio1">
          <label>
            <input type="radio" name="endorsementtype" value="type1"     id="endorsementtype_0" />
            Personal</label>
          <br />
          <label>
            <input type="radio" name="endorsementtype" value="type2"     id="endorsementtype_1" />
            Professional</label>
          <br />
          <label>
            <input type="radio" name="endorsementtype" value="type3"     id="endorsementtype_2" />
            Organization</label>
          <br />
          <span class="radioRequiredMsg">Please make a selection.</span>    </span></p>
        <p>Endorsment Quote:</p>
        <p><span id="sprytextarea1">
          <textarea name="endorsementquote" id="endorsementquote" cols="45"  rows="5"></textarea>
          <span class="textareaRequiredMsg">*</span></span></p>
        <p>
          <input type="submit" name="submit" id="submit" value="Submit" />
          <input type="reset" name="reset" id="reset" value="Clear Form" />
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • is the email filled in the message? – BHoft Jan 15 '16 at 14:58
  • Firstly, does your *real* code contain the closing `` tag? It's not in there. – Funk Forty Niner Jan 15 '16 at 15:02
  • Plus, given the ID's and ones for the form, I'd say you're probably using JS somewhere but didn't mention that. – Funk Forty Niner Jan 15 '16 at 15:04
  • *"but not the data from who fills it out"* - Ok, so you're not checking if any of your inputs are empty. No idea how to "answer" this, but I could. However, I stand the chance at being wrong given your question and possible missing code and the one I said about the missing `` tag. – Funk Forty Niner Jan 15 '16 at 15:07

2 Answers2

0

Consult my footnote.

Given the probable missing </form> tag in your question (something I commented on under your question), you're not checking if any of your inputs are empty, in turn leading to no data sent in mail.

You need to use a conditional !empty() against your inputs.

Sidenote: The && logical operator means AND. You can also use the || being the logical OR operator, depending on what you wish to check for.

I.e.:

 if(!empty($_POST['var1']) && !empty($_POST['var2']) ) 
 {

 // run your code

 }

which you can add to that with your other POST arrays.

Reference:

Plus, if your HTML form and PHP are inside the same file (which is unknown but probable), that will also send empty data.

Therefore, use a conditional isset() for your submit button, followed by the conditional empty() inside that.

You're also open to an XSS injection with the POST arrays inside the $message variable.

Assign variables to POST arrays, and use validation filters.

You also have a syntax error at the end here:

"Endorsement Quote  " . $_POST['endorsementquote'] . "\r\n" ."\r\n" .

You did not close it properly, if that's your actual code.

If should contain a closing semi-colon and losing the last dot:

"Endorsement Quote  " . $_POST['endorsementquote'] . "\r\n" ."\r\n";

Error reporting would have caught that.


Footnote:

Edit: As noted by Riggs.

You need to remove enctype="text/plain"

I didn't see that passed what is shown. But my answer above still applies and you should be doing that, because you will still end up with probable empty data.

Here is an article on that here on Stack:

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

Remove the enctype= property from your <form> tag to let it default to application/x-www-form-urlencoded or change the encytpe to

enctype="application/x-www-form-urlencoded"

Also @Fred-ii- makes a lot of good points

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149