-1

If I submit the form I only get an email in my mailbox, with no information. How can i fix this?

PHP code:

<?php
$to      = 'julius.kroon@gmail.com';
$subject = 'new costumer';
if(isset($_POST['title'])){ $title = $_POST['title']; }
if(isset($_POST['name'])){ $name = $_POST['name']; }
if(isset($_POST['companyname'])){ $companyname = $_POST['companyname']; }
if(isset($_POST['mail'])){ $mail = $_POST['mail']; }
if(isset($_POST['extrapages'])){ $extrapages = $_POST['extrapages']; }
if(isset($_POST['sow'])){ $sow = $_POST['sow']; }
$title = null;
$name = null;
$companyname = null;
$mail = null;
$extrapages = null;
$sow = null;
$message ="
title = $title
name = $name
companyname = $companyname
mail = $mail
extra pages = $extrapages
site on web = $sow";
$headers = 'From: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

HTML code:

<form action="" method="POST" enctype="text/plain">
    <em>Last name:</em></br>
    <select name="title" id="title">
        <option>Mr.</option>
        <option>Mrs.</option>
        <option>Dr.</option>
    </select>
    <input type="text" size="25" name="name" id="name" placeholder="Last name"><p /><br>

    <em>company name:</em></br>
    <input type="text" size="25" name="companyname" id="companyname" placeholder="Company Name"><p /><br>

    <em>Email:</em></br>
    <input type="text" size="25" name="mail" id="mail" placeholder="email"><p /><br>

    <em>how many extra pages:</em><br>
    <select name="extrapages" id="extrapages">
        <option>0</option>
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
    </select><br><br>

    <em>Would you like us to put your site on the internet?</em><br>
    <input type="radio" name="sow" id="sow" value="Yes">Yes
    <input type="radio" name="sow" id="sow" value="No">No<br><br>
    <input type="Submit" value="Send!">
</form>

If I submit the form I only get the following text in my email:

title =
name =
companyname =
mail =
extra pages =
site on web =

What do I have to do to fix this?

julius174
  • 23
  • 2

1 Answers1

1

This is your first problem:

enctype="text/plain" 

PHP doesn't support that encoding of form data and won't populate $_POST if given data in that format. Remove it.

Your second problem is here:

$title = null;
$name = null;
$companyname = null;
$mail = null;
$extrapages = null;
$sow = null;

After collecting the data from $_POST… you throw it away. Don't do that. Remove those lines.

now i get the error :Undefined variable. how do i solve this error?

This is covered in this question.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335