Skip to main content
saimib
Participant
November 3, 2016
Answered

php form variables are not included in email

  • November 3, 2016
  • 3 replies
  • 932 views

Hello,

I made a form in html with an php linked to it, so people can fill out my contact form and I get an email. However, my variables are not inlcuded in the mail I get...

Can you guys help me?

This topic has been closed for replies.
Correct answer BenPleysier

De markup (HTML)

<form method="" name="myemailform" action="email-form.php">

  <div class="form-group">

  <input type="name" class="form-control form-control-white" id="name" placeholder="Uw naam" name="fullname" required/>

  </div>

  <div class="form-group">

  <input name="email" type="email" required class="form-control form-control-white" id="email" placeholder="Email"/>

  </div>

  <div class="form-group">

  <input type="message" class="form-control form-control-white" id="message" placeholder="Bericht" name="message" required/>

  </div>

  <input type="submit" class="btn btn-o-white" value="Verstuur"/>

</form>

email-form.php

<?php

  $Subject = 'ingevuld formulier op de website';

  $webmaster = 'info@xxxxxxxxrs.be';

  $emailfield = $_POST['email'];

  $namefield = $_POST['fullname'];

  $messagefield = $_POST['message'];

  $body = <<<EOD

<br><hr><br>

Email: $emailfield <br>

Naam: $namefield <br>

Bericht: $messagefield <br>

EOD;

  $headers = "From: $emailfield\r\n";

  $headers .= "Content-type: text/html\r\n";

  $success = mail($webmaster, $Subject, $body, $headers);

echo "Bedankt voor uw bericht! Klik <a href='http://www.saimibauters.be/index.html'> hier </a> om terug te gaan!";

?>

EDIT: mail adres van webmaster veranderd, anders zullen email harvesters een vroege Sinterklaas hebben. Normale adres gebruiken in de code.

3 replies

saimib
saimibAuthor
Participant
November 3, 2016

thanks for your help!!!

Rob Hecker2
Legend
November 3, 2016

Ben has answered your question, but you should realize that hackers love forms like this because it is completely unprotected.

There are two problems:

  1. The form will be hounded by spam bots. Do a google search for "protect email form with honeypot"
  2. The variables sent to the PHP script must be sanitized and validated. Read about PHP FILTER_VALIDATE
BenPleysier
Community Expert
Community Expert
November 3, 2016

Thanks for that Rob. You are entirely right. The OP may like to have a look at Nancy's tutorial at Alt-Web Design & Publishing: Responsive Contact Form with Bootstrap 3.2 and PHP (Part 1)

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
saimib
saimibAuthor
Participant
November 3, 2016

<?php

  $Subject = 'ingevuld formulier op de website';

  $webmaster = 'info@xxxxxxxxxxxxrs.be';  [Mod changed the email address]

  $emailfield = $_POST['email'];

  $namefield = $_POST['fullname'];

  $messagefield = $_POST['message'];

  $body = <<<EOD

<br><hr><br>

Email: $email <br>

Naam: $fullname <br>

Bericht: $message <br>

EOD;

  $headers = "From: $email\r\n";

  $headers .= "Content-type: text/html\r\n";

  $success = mail($webmaster, $Subject, $body, $headers);

echo "Bedankt voor uw bericht! Klik <a href='http://www.saimibauters.be/index.html'> hier </a> om terug te gaan!";

?>

This is the code for my php form

  <form method="" name="myemailform" action="email-form.php">
<div class="form-group">

                                    <input type="name" class="form-control form-control-white" id="name" placeholder="Uw naam" required/>

</div>
    <div class="form-group">
<input name="email" type="email" required class="form-control form-control-white" id="email" placeholder="Email"/>
    </div>
    <div class="form-group">
<input type="message" class="form-control form-control-white" id="message" placeholder="Bericht" required/>

                                        </div>

  <input type="submit" class="btn btn-o-white" value="Verstuur"/>

</form>

and this my html form

BenPleysier
Community Expert
BenPleysierCommunity ExpertCorrect answer
Community Expert
November 3, 2016

De markup (HTML)

<form method="" name="myemailform" action="email-form.php">

  <div class="form-group">

  <input type="name" class="form-control form-control-white" id="name" placeholder="Uw naam" name="fullname" required/>

  </div>

  <div class="form-group">

  <input name="email" type="email" required class="form-control form-control-white" id="email" placeholder="Email"/>

  </div>

  <div class="form-group">

  <input type="message" class="form-control form-control-white" id="message" placeholder="Bericht" name="message" required/>

  </div>

  <input type="submit" class="btn btn-o-white" value="Verstuur"/>

</form>

email-form.php

<?php

  $Subject = 'ingevuld formulier op de website';

  $webmaster = 'info@xxxxxxxxrs.be';

  $emailfield = $_POST['email'];

  $namefield = $_POST['fullname'];

  $messagefield = $_POST['message'];

  $body = <<<EOD

<br><hr><br>

Email: $emailfield <br>

Naam: $namefield <br>

Bericht: $messagefield <br>

EOD;

  $headers = "From: $emailfield\r\n";

  $headers .= "Content-type: text/html\r\n";

  $success = mail($webmaster, $Subject, $body, $headers);

echo "Bedankt voor uw bericht! Klik <a href='http://www.saimibauters.be/index.html'> hier </a> om terug te gaan!";

?>

EDIT: mail adres van webmaster veranderd, anders zullen email harvesters een vroege Sinterklaas hebben. Normale adres gebruiken in de code.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
BenPleysier
Community Expert
Community Expert
November 3, 2016

The posted values come from the name attribute as in

<input name="fullname" type="text" required="true" class="form-control" id="fullname" placeholder="full name">

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
saimib
saimibAuthor
Participant
November 3, 2016

that doesn't seem to work...

BenPleysier
Community Expert
Community Expert
November 3, 2016

Rather than a screen shot, please supply the code that is being used by copying and pasting here.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!