我是一个完整的PHP新手。我有一个联系表格,在提交表格时向我发送电子邮件,但电子邮件的正文是完全空的。我在网上尝试或查找/研究过的所有东西都没有用。我不知道我的代码有什么问题。正如我之前提到的,我不知道我正在用这个PHP做什么(HTML和CSS是关于我可以处理的所有内容)。我提前道歉,我需要大量的手段来解决这个问题!如果有人可以帮助我,我会永远感激。谢谢,麻烦您了!我的代码粘贴在下面,出于安全原因,我已经更改了电子邮件地址。另外,我们也在我们的网络服务器上运行最新版本的php,如果有帮助的话。
我的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"> </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>
我的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 . ' </td><td> ' . $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();
?>
答案 0 :(得分:0)
你关闭了多少?
<textarea rows="4" name="Role/Responsibilities" />
</textarea>
</textarea>
</textarea>