-2

I have a problem with my contact form

Filling in the form is OK etc, but when I send the message, I only receive the telephone nr.

This is PHP code from sendmail.

<?php
if (isset($_POST["submit"])) {
    // Checking For Blank Fields..
    if ($_POST["name"] == "" || $_POST["email"] == "" || $_POST["tel"] == "") {
        echo "Fill All Fields..";
    } else {
        // Check if the "Sender's Email" input field is filled out
        $email = $_POST['email'];
        // Sanitize E-mail Address
        $email = filter_var($email, FILTER_SANITIZE_EMAIL);
        // Validate E-mail Address
        $email = filter_var($email, FILTER_VALIDATE_EMAIL);
        if (!$email) {
            echo "Invalid Sender's Email";
        } else {
            $subject = 'neuen Kontakt';
            $message = $_POST['name'];
            $message = $_POST['email'];
            $message = $_POST['tel'];
            $headers = 'From:' . $email2 . "\r\n"; // Sender's Email
            $headers .= 'Cc:' . $email2 . "\r\n"; // Carbon copy to Sender
            // Message lines should not exceed 70 characters (PHP rule), so wrap it
            //$message = wordwrap($message, 70);
            // Send Mail By PHP Mail Function
            mail("mymail@gmail.com", $subject, $message, $headers);
            echo "Your mail has been sent successfuly ! Thank you for your feedback";
        }
    }
}
?>

and this is the html form

<form action="index.php" method="post" name="contactus" id="contactus" onsubmit="return ValidateForm();">
<table width="260" border="0" cellspacing="0" cellpadding="0" align="center" style="color:#FFF">
    <tr>
        <td height="25px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">Name<span style="color:#F00">*</span>
        </td>
    </tr>
    <tr>
        <td style="padding:0 0 0 10px;">
            <input name="name" type="text" class="input" id="name" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="" />
        </td>
    </tr>
    <tr>
        <td height="27px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">Telefonnummer<span style="color:#F00">*</span>
        </td>
    </tr>
    <tr>
        <td class="td_style1">
            <input name="tel" type="text" class="input" id="email" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="" />
        </td>
    </tr>
    <tr>
        <td height="25px" style="font-family:Arial; font-size:13px; color:#575757; padding:0 0 0 10px;">E-mail<span style="color:#F00">*</span>
        </td>
    </tr>
    <tr>
        <td style="padding:0 0 0 10px;">
            <input name="email" type="text" class="input" id="email" onFocus="inputFocus(this)" onBlur="inputBlur(this)" value="email@gmail.com" />
        </td>
    </tr>
    <tr>
        <td style="padding:10px 28px 0 0;" align="right">
            <input name="submit" type="submit" value="SUBMIT" class="submit" />
        </td>
    </tr>
    <tr>
        <td height="20px" style="font-family:Arial; font-size:11px; color:#575757; padding:3px 27px 0 0px; float:right;"><span style="color:#F00">*</span> sind Pflichtfelder</td>
    </tr>
</table>

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • 2
    You overwrite `$message` every time. You could possibly concatenate the strings like `$message .= $_POST['email']; $message .= $_POST['tel'];` which seems to be what you want to start with? (the dot in front of `=`) – Qirel Oct 19 '16 at 11:05
  • I want to come in message something like: name,email,tel... but i receive only tel number.. –  Oct 19 '16 at 11:08
  • Did you even read the comment above...? It explains exactly that. – Qirel Oct 19 '16 at 11:09
  • Question is off topic. – Funk Forty Niner Oct 19 '16 at 11:12

2 Answers2

3

You overwrite the $message with each field so you will get only the last one (tel). You need to concatenate all the fields using . like this:

$message = $_POST['name'] . ", ";
$message .= $_POST['email'] . ", " ;
$message .= $_POST['tel'];

Or you can do in one line like this:

$message = $_POST['name'] . ", " . $_POST['email'] . ", "  . $_POST['tel'];

Also you can add a comma or something like that between the fields so will not be glued together.

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
0

You are replacing value of $message everytime with new value , and at end it is assigned to telephone so u only recieve telephone no

Replace

 $message = $_POST['name'];
 $message = $_POST['email'];
 $message = $_POST['tel'];

With

$message =$_POST['name'];
$message =$message.$_POST['email'];
$message =$message.$_POST['tel'];
mahethekiller
  • 514
  • 3
  • 17