Skip to main content
Participating Frequently
July 19, 2017
Answered

Problem PHP-Mailscript - mail arrives, but no content...

  • July 19, 2017
  • 3 replies
  • 504 views

Hi everyone,

for a contact form i have these two pages and code:

-----------------

contact.html:

-----------------

(...)

  <div class="row">

    <div class="text-justify col-sm-12">

        <form action="sendmail_test-2017-07-15.php" method="POST"  class="form-horizontal">   

           <div  class="form-group">

        <label  for="inputfirstname"  class="control-label col-sm-2">First Name</label>

        <div  class="col-sm-10">

            <input  type="text" required  class="form-control"  id="inputfirstname"  placeholder="Put in your First Name--here">

        </div>

    </div>

    <div  class="form-group">

        <label  for="inputlastname"  class="control-label col-sm-2">Last Name</label>

        <div  class="col-sm-10">

            <input  type="text" required  class="form-control"  id="inputlastname"  placeholder="Put in your Last Name">

        </div>

    </div>

  

    <div  class="form-group">

        <label  for="inputsendermail"  class="control-label col-sm-2">e-mail</label>

        <div  class="col-sm-10">

            <input  type="text" required  class="form-control"  id="inputsendermail"  placeholder="Put in your e-mail-address">

         </div>

    </div>  

   

    <div  class="form-group">

        <label  for="inputcontactnumber"  class="control-label col-sm-2">Contact #</label>

        <div  class="col-sm-10">

             <input  type="text" required  class="form-control"  id="inputcontactnumber"  placeholder="Put in your Contact Number">

        </div>

    </div>    

    <div  class="form-group">

        <label  for="inputsubject"  class="control-label col-sm-2">Subject</label>

        <div  class="col-sm-10">

             <input  type="text" required  class="form-control"  id="inputsubject"  placeholder="Put in your Subject">

        </div>

    </div> 

  

    <div  class="form-group">

        <label  for="message"  class="control-label col-sm-2">Message</label>

        <div  class="col-sm-10">

              <textarea rows="3" required class="form-control"  id="message" placeholder="Put in your Message"></textarea>

        </div>

    </div>

  

    <div class="form-group">

        <div class="col-sm-offset-2 col-sm-10">

            <!--  Du  Zuweisung  class="btn  btn-primary  macht  aus  der  Schaltflaeche  einen  schoenen  blauen  Button  --> 

            <button  class="btn  btn-primary"  type="submit">Send</button>

        </div>

    </div>

</form>   

    </div>

<hr>

 

</div>

-------------------------

------------------------------

sendmail_test-2017-07-15.php

------------------------------

<?php

/* === Daten aus dem Formular auslesen und in Variablen speichern === */

  $vorname = $_POST&#91;'inputfirstname'&#93;;

  $nachname = $_POST&#91;'inputlastname'&#93;;

  $email = $_POST&#91;'inputsendermail'&#93;;

  $betreff = $_POST&#91;'inputsubject'&#93;;

  $nachricht = $_POST&#91;'message'&#93;;

  $name = $vorname.' '.$nachname;

/* === Empfängeradresse und Betreff === */

  $an = 'mail@stefan-bee.de'; //Hier Ihre E-Mail-Adresse eintragen

  $betreff = "Kontaktformularnachricht | $betreff | $name ";

{mail($an, $betreff, $nachricht, 'From:' . $email); //Mail versenden

      echo 'Ihre Kontaktnachricht wurde zugestellt. Sie werden bald möglichst eine Antwort erhalten.';

    }

?>

-------------------------

Both files are saved in the same directory.

The E-Mail arrives, and the fixed parameters ("an" / "betreff") are okay - but the problem is: the variables won't arrive - means: no name, no sender-email, no message ("nachricht").

What is wrong with the script?

Thank you very much in advance!

Stefan

This topic has been closed for replies.
Correct answer osgood_

First thing I can see is you have no name="" attributes in your form input tags (see in red below). php requires those to get the value from the form field.

<input  type="text" required  class="form-control"  name="inputfirstname" id="inputfirstname"  placeholder="Put in your First Name--here">

$vorname = $_POST['inputfirstname'];

PHP form processing script :

<?php

//get information from form fields

$vorname = $_POST['inputfirstname'];

$nachname = $_POST['inputlastname'];

$email = $_POST['inputsendermail'];

$betreff = $_POST['inputsubject'];

$nachricht = $_POST['message'];

//to email address/from email address and email subject

$an = "recipient_email_address.com';// change to email address you want information sent to

$email_from = 'your_server@yourdomain.com';// change to show email comes from your server

$email_subject = "Message from your website";

// You then need to build your email 'message'

$email_body = "You have received a new message.\n";

$email_body .= "First Name: $vorname\n";

$email_body .= "Last Name: $nachname\n";

$email_body .= "Email: $email\n";

$email_body .= "Message: $nachricht\n";

// additional headers

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

$headers .= "Reply-To: $email \r\n";

//send the email

mail($an, $email_subject, $email_body, $headers);

?>

You should make a validation check on the supplied email at least. This is just an example of a basic form processing script.

3 replies

Participating Frequently
July 22, 2017

hey all, thank you for your great help!! I'll try to test it and give you further feedback asap.

Nancy OShea
Community Expert
Community Expert
July 20, 2017
Nancy O'Shea— Product User & Community Expert
osgood_Correct answer
Legend
July 19, 2017

First thing I can see is you have no name="" attributes in your form input tags (see in red below). php requires those to get the value from the form field.

<input  type="text" required  class="form-control"  name="inputfirstname" id="inputfirstname"  placeholder="Put in your First Name--here">

$vorname = $_POST['inputfirstname'];

PHP form processing script :

<?php

//get information from form fields

$vorname = $_POST['inputfirstname'];

$nachname = $_POST['inputlastname'];

$email = $_POST['inputsendermail'];

$betreff = $_POST['inputsubject'];

$nachricht = $_POST['message'];

//to email address/from email address and email subject

$an = "recipient_email_address.com';// change to email address you want information sent to

$email_from = 'your_server@yourdomain.com';// change to show email comes from your server

$email_subject = "Message from your website";

// You then need to build your email 'message'

$email_body = "You have received a new message.\n";

$email_body .= "First Name: $vorname\n";

$email_body .= "Last Name: $nachname\n";

$email_body .= "Email: $email\n";

$email_body .= "Message: $nachricht\n";

// additional headers

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

$headers .= "Reply-To: $email \r\n";

//send the email

mail($an, $email_subject, $email_body, $headers);

?>

You should make a validation check on the supplied email at least. This is just an example of a basic form processing script.