0

I'm using a the following to have a contact page send me a email with visitors data.

            <form method="post" action="submit.php">
            <label for="Name">Name</label>
            <input type="text" name="Name" id="Name" />

            <label for="Email">eMail</label>
            <input type="text" name="Email" id="Email" />



            <input type="submit" name="submit" value="Send" class="submit-button" />
            </form>

and the php:

    <?php

    $EmailFrom = "Me";
    $EmailTo = "me@me.com";
    $Subject = "Test";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 

    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "eMail: ";
    $Body .= $Email;
    $Body .= "\n";

    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>

When trying it out I only get the email body text prepared by the PHP file but none of the information inserted by the visitor, like this:

Name: eMail:

no0ne
  • 2,659
  • 8
  • 28
  • 44

2 Answers2

0

Try to set header information for E-Mail:

$header  = 'MIME-Version: 1.0'."\r\n";
$header .= 'Content-type: text/plain; charset=iso-8859-1'."\r\n";
$header .= 'From: '.$EmailFrom."\r\n";

$success = mail($EmailTo, $Subject, $Body, $header);
WolvDev
  • 3,182
  • 1
  • 17
  • 32
0

In the end I just simplified it a little bit.. also it seemed to be a "case sensitive" issue that stopped the form to communicate with the php file.

So this is what worked in the end:

            <form method="post" action="submit.php">
            <label for="Name">Name</label>
            <input type="text" name="Name" id="name" />

            <label for="Email">eMail</label>
            <input type="text" name="Email" id="email" />

            <label for="Message">Message</label>
            <textarea name="Message" rows="10" id="message"></textarea>

            <input type="submit" name="submit" value="Send" class="submit" id="submit"/>
            </form>

and the php:

        <?php


    $EmailFrom = "Test";
    $EmailTo = "test@test.com";
    $Subject = "Testing";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Message = Trim(stripslashes($_POST['Message'])); 

    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "eMail: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
no0ne
  • 2,659
  • 8
  • 28
  • 44