联系表格不发送所有数据

时间:2016-10-19 11:02:51

标签: php html email email-integration email-validation

我的联系表格有问题

填写表格是好的等等,但是当我发送信息时,我只收到电话号码。

这是sendmail的PHP代码。

<?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";
        }
    }
}
?>

这是html表单

<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>

2 个答案:

答案 0 :(得分:3)

您在每个字段中覆盖$message,因此您只会获得最后一个字段(tel)。您需要使用.连接所有字段,如下所示:

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

或者你可以这样做一行:

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

此外,您可以在字段之间添加逗号或类似内容,这样就不会粘在一起。

答案 1 :(得分:0)

您每次都使用新值替换$ message的值,最后将其分配给电话,因此您只接收电话号码

替换

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

使用

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