简体   繁体   English

为什么我的PHP联系人表格发送的邮件正文(消息)为空白?

[英]Why is my PHP contact form is sending emails with the body (message) blank?

I am a complete PHP newbie. 我是一个完整的PHP新手。 I have a contact form which is sending me the email upon submitting the form, but the body of the email is completely empty. 我有一个联系表单,在提交表单后会向我发送电子邮件,但是电子邮件正文完全为空。 Everything I've tried or looked up/researched online has not worked. 我在网上尝试或查找/搜索过的所有内容均无效。 I have no idea what is wrong with my code. 我不知道我的代码有什么问题。 As I mentioned before, I have no idea what I'm doing with this PHP (HTML and CSS are about all I can handle). 如前所述,我不知道我在用这个PHP做些什么(HTML和CSS就是我能处理的全部)。 I apologize in advance, I need a serious amount of handholding to fix this! 我预先表示歉意,需要大量处理才能解决此问题! If someone could help me with this I would be eternally grateful. 如果有人可以帮助我,我将永远感激不已。 Please and thank you! 谢谢,麻烦您了! My code is pasted below, I've changed the email address's for security reasons. 我的代码粘贴在下面,出于安全原因,我更改了电子邮件地址。 Also, we are running the latest version of php on our web server's as well, if that helps. 另外,如果有帮助,我们也在网络服务器上运行最新版本的php。

My HTML: 我的HTML:

<table>
<tr>
    <td valign="top" align="left">
        <form action="BRF-sendForm.php" method="post" enctype="x-www-form-encoded">
            <table width="647" border="0" align="center" cellpadding="10" cellspacing="0">
                <tr align="middle" valign="middle">
                    <td colspan="2" style="text-align: center; font-size: 20px;"><strong>Biography Request Form</strong></td>
                </tr>
                <tr align="left" valign="middle">
                    <td width="40%">*First Name</td>
                    <td width="60%"><input name="FirstName" id="FirstName" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Middle Name<br />
                        (If you would like it to appear)</td>
                    <td><input name="MiddleName" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>*Last Name</td>
                    <td><input name="LastName" id="LastName" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>*Email</td>
                    <td><input name="Email" id="Email" type="text" /></td>
                </tr>
                <tr>
                <tr align="left" valign="middle">
                    <td>Title</td>
                    <td><input name="Title" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Organization</td>
                    <td><input name="Organization" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Years in Current Role</td>
                    <td><input name="Years in Current Role" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Role/Responsibilities</td>
                    <td><textarea rows="4" name="Role/Responsibilities" />
                        </textarea>
                        </textarea>
                        </textarea></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Credentials</td>
                    <td><input name="Credentials" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Years Experience</td>
                    <td><input name="Years Experience" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>City and State of Residence</td>
                    <td><input name="City and State of Residence" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Notable Companies of Previous Employment<br />
                        (Include title(s) held)</td>
                    <td><textarea  rows="4" name="Notable Employment" />
                        </textarea>
                        </textarea>
                        </textarea></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Awards (include year awarded)</td>
                    <td><textarea  rows="4" name="Awards" />
                        </textarea>
                        </textarea>
                        </textarea></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Professional Organizations/Affiliations</td>
                    <td><input name="Professional Organizations/Affiliations" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Previous Title(s) with Current Organization (include years):</td>
                    <td><input name="Previous Title(s) with Current Organization" type="text" /></td>
                </tr>
            </table>
            <table width="647" border="0" align="center" cellpadding="10" cellspacing="0" class="pageBreak">
                <tr>
                    <td colspan="2"style="font-size:17px;"><br />
                        <strong>Education</strong></td>
                </tr>
                <tr align="left" valign="middle">
                    <td width="40%">Name of School, College or University</td>
                    <td width="60%"><input name="School Name" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Degree</td>
                    <td><input name="Degree" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Year Completed</td>
                    <td><input name="Year Completed" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Name of School, College or University</td>
                    <td><input name="School Name" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Degree</td>
                    <td><input name="Degree" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Year Completed</td>
                    <td><input name="Year Completed" type="text" /></td>
                </tr>
            </table>
            <table width="647" border="0" align="center" cellpadding="10" cellspacing="0">
                <tr>
                    <td colspan="2" style="font-size:17px;"><br />
                        <strong>Veteran Status</strong></td>
                </tr>
                <tr align="left" valign="middle">
                    <td width="40%">Branch</td>
                    <td width="60%"><input name="Branch" type="text" /></td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Years Served</td>
                    <td><input name="Years Served" type="text" /></td>
                </tr>
                <tr>
                    <td colspan="2">&nbsp;</td>
                </tr>
                <tr align="left" valign="middle">
                    <td>Personal</td>
                    <td><textarea  rows="4" name="Personal" />
                        </textarea>
                        </textarea>
                        </textarea></td>
                </tr>
                <td colspan="2" style="text-align: center;"><input name="submit" type="submit" value="Submit Form" /></td>
                </tr>
            </table>
        </form>
    </td>
</tr>

My PHP: 我的PHP:

    <?
ob_start();
$now = date('l jS \of F Y h:i:s A');


if (check_data()){
    // Send E-Mail
    echo '<h1 style="margin-top: 20px; text-align:center;">Biography Request Form</h1>';

    send_mail();
    echo '<p style="text-align:center;">Thank you! Your form has been submitted.</p>';
}
else{
    echo '<p style="text-align:center;">Please correct the above errors, and submit your form again. If you are having trouble submitting this form please contact <a href="email@test.com">email@test.com</a></p>';

    exit();
}


function verifyData($str_to_test) {
  $bad_strings = array(
                "content-type:"
                ,"mime-version:"
                ,"multipart/mixed"
                ,"Content-Transfer-Encoding:"
                ,"bcc:"
                ,"cc:"
                ,"to:"
  );

  foreach($bad_strings as $bad_string) {
    if(eregi($bad_string, strtolower($str_to_test))) {
      showerror("$bad_string found. Suspected injection attempt - mail not being sent.");

    }
  }
}

function contains_newlines($str_to_test) {
   if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
     showerror("newline found in $str_to_test. Suspected injection attempt - mail not being sent.");
     exit;
   }
} 

function check_data(){

    // also inspects data for hacking attempts (via verifyData).
    // if verifyData finds something suspicious, the page exists with a warning.
    $isok = true;
    // Check for a person's name.
    if (eregi ("^[[:alnum:].' -]{1,100}", stripslashes(trim($_POST['FirstName'])))) {
    } else {
        $isok = false;
        $errors[] = '<p style="color: #F00; text-align: center;">Please enter your first name!</p>';
    }
    if (eregi ("^[[:alnum:].' -]{1,100}", stripslashes(trim($_POST['LastName'])))) {
    } else {
        $isok = false;
        $errors[] = '<p style="color: #F00; text-align: center;">Please enter your last name!</p>';
    }
    if (eregi ("^[[:alnum:].' -]{1,100}", stripslashes(trim($_POST['Email'])))) {
    } else {
        $isok = false;
        $errors[] = '<p style="color: #F00; text-align: center;">Please enter your email!</p>';
    }
    if (!$isok){
        foreach($errors as $err)
        echo '<div>' . $err . '</div>';
        return false;
    }


    // look for hacker codes.
    verifyData($_POST['Address']);
    verifyData($_POST['City']);
    verifyData($_POST['State']);
    verifyData($_POST['State']);
    verifyData($_POST['Zip']);
    verifyData($_POST['Email']);


    if($_SERVER['REQUEST_METHOD'] != "POST"){
       showerror("Unauthorized attempt to access page.");
    }
    return true;
}

function send_mail(){


    $to = 'email@test.com'; 
    $subject = "Test Mail";

    $txt = "<p>Below is the result of your feedback form.  It was submitted by</p>";
    $txt .= "<table>";
    foreach($_POST AS $field => $value) {
        if (substr($field, 0, 12) == 'Send_info_on')
            $field = 'Box checked:';
        $printIt = true;
        if (substr($field, 0, 18) == 'more_info_on_other'){
                if ($value > ' '){
                    $field = 'Box checked:';
                }else{
                    $printIt = false;
                }
        }

        if ($field == 'submit'){
            $printIt = false;
        }

        if ($printIt){
            $txt .= '<tr><td>' . $field . '&nbsp;</td><td>&nbsp;' . $value . '</td></tr>';
        }
    }
    $txt .= '</table>';
    //echo $txt;

    // Always set content-type when sending HTML email
    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "From: webmaster@test.com" . "\r\n";
    $headers .= "CC: email@test.com". "\r\n";

    mail($to,$subject,$txt,$headers);


}

function showerror($msg) { 
  ?>
<html>
<head>
<title>Sorry, Please Try Again</title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<center>
    <table border=0 width=600 bgcolor=#9C9C9C>
        <tr>
            <th><font size=+2>Oops!</font></th>
        </tr>
    </table>
    <table border=0 width=600 bgcolor=#CFCFCF>
        <tr>
            <td>Something you entered did not pass our security checks.</td>
        <tr>
            <td><? echo $msg ?></td>
        </tr>
        <tr>
            <td>Please check your data, then submit again.</td>
        </tr>
    </table>
</center>
</body>
</html>
<?
ob_end_flush();
exit();

}
ob_end_flush();
?>

How many you are closing?? 您要关闭多少?

   <textarea rows="4" name="Role/Responsibilities" />
                    </textarea>
                    </textarea>
                    </textarea>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM