我多次从这个网站获得帮助,但这是我第一次发布我自己的细节。
我有一个PHP注册表单,我确定这是一个小问题,但我不知道完全我需要修复的内容。所以,我很欣赏有人看过它。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "c@d.com";
$email_subject = "Form Submitted";
$email_from = "c@d.com";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Agency']) ||
!isset($_POST['AgencyPhone'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Agency = $_POST['Agency']; // required
$AgencyPhone = $_POST['AgencyPhone']; // required
$contact = $_POST['contact']; // not required
...this goes on for quite some time...
$Zip = $_POST['Zip']; // not required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Agency)) {
$error_message .= 'The Agency Name you entered does not appear to be valid.<br />';
}
if(strlen($AgencyPhone) < 2) {
$error_message .= 'The Agency Phone you entered does not appear to be valid.<br />';
}
$email_message = "You received a message from your site!\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message="
Class: ".$contact."
Dates: ".$Dates." through ".$through."
Location: ".$Location."
Fee: ".$Fee.", ".$Rate."
Students:
1: ".$Last1.", ".$First1.", ".$Email1.", ".$Phone1."\n;
2: ".$Last2.", ".$First2.", ".$Email2.", ".$Phone2."\n;
3: ".$Last3.", ".$First3.", ".$Email3.", ".$Phone3."\n;
4: ".$Last4.", ".$First4.", ".$Email4.", ".$Phone4."\n;
5: ".$Last5.", ".$First5.", ".$Email5.", ".$Phone5."\n;
Agency: ".$Agency.";
Mailing: ".$Mailing.";
City: ".$City.";
Zip: ".$Zip.";
Agency Phone: ".$AgencyPhone.";
"
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
...Then, I have the content of the process page...
<!-- Do not change anything below this line -->
<?php
}
?>
所以,错误在这一行。
$headers = 'From: '.$email_from."\r\n".
或者,无论如何, 错误。缺少什么,或者我需要添加什么?感谢您提供的任何帮助。我真的很感激。
我的表格是:
<form action="Rprocess.php" method="post" enctype="multipart/form-data" class="body">
<p><span class="title">Enter Class Date, Location and Fee</span><br />
<span class="style3">for which you are registering</span>:</p>
<p align="left" class="style1">Dates:
<input type="text" name="Dates" size="15" id="Dates" />
through
<input type="text" name="through" size="15" id="through" />
</p>
<p align="left" class="style1">Location:
<input type="text" name="Location" size="48" id="Location" />
</p>
<div class="field form-inline radio2">
<table width="100%" border="0" cellspacing="2">
<tr>
<td width="509"><span class="style1">Registration Fee:
<input name="Fee" type="text" id="Fee" value="$" size="15" />
per student</span></td>
</tr>
</table>
<p class="style1">Please fill in fields below.<br />
<span class="style3">(Confirmation e-mail will be forwarded to attendee and Registrant Agency upon receipt.)</span></p>
<p><span class="title">Student Information</span>:</p>
<table width="100%" border="0" cellspacing="2">
<tr>
<td width="25%"><span class="style1">Last</span></td>
<td><span class="style1">First</span></td>
<td width="25%"><span class="style1">E-mail</span></td>
<td width="25%"><span class="style1">Phone</span></td>
</tr>
<tr>
<td width="25%"><span class="style1">
<input type="text" name="Last1" size="15" id="Last1" />
</span></td>
<td><span class="style1">
<input type="text" name="First1" size="15" id="First1" />
</span></td>
<td width="25%"><span class="style1">
<input type="text" name="Email1" size="15" id="Email1" />
</span></td>
<td width="25%"><span class="style1">
<input type="text" name="Phone1" size="15" id="Phone1" />
</span></td>
</tr>
<tr>
<td><span class="style1">
<input type="text" name="Last2" size="15" id="Last2" />
</span></td>
<td><span class="style1">
<input type="text" name="First2" size="15" id="First2" />
</span></td>
<td><span class="style1">
<input type="text" name="Email2" size="15" id="Email2" />
</span></td>
<td><span class="style1">
<input type="text" name="Phone2" size="15" id="Phone2" />
</span></td>
</tr>
<tr>
<td><span class="style1">
<input type="text" name="Last3" size="15" id="Last3" />
</span></td>
<td><span class="style1">
<input type="text" name="First3" size="15" id="First3" />
</span></td>
<td><span class="style1">
<input type="text" name="Email3" size="15" id="Email3" />
</span></td>
<td><span class="style1">
<input type="text" name="Phone3" size="15" id="Phone3" />
</span></td>
</tr>
<tr>
<td><span class="style1">
<input type="text" name="Last4" size="15" id="Last4" />
</span></td>
<td><span class="style1">
<input type="text" name="First4" size="15" id="First4" />
</span></td>
<td><span class="style1">
<input type="text" name="Email4" size="15" id="Email4" />
</span></td>
<td><span class="style1">
<input type="text" name="Phone4" size="15" id="Phone4" />
</span></td>
</tr>
<tr>
<td><span class="style1">
<input type="text" name="Last5" size="15" id="Last5" />
</span></td>
<td><span class="style1">
<input type="text" name="First5" size="15" id="First5" />
</span></td>
<td><span class="style1">
<input type="text" name="Email5" size="15" id="Email5" />
</span></td>
<td><span class="style1">
<input type="text" name="Phone5" size="15" id="Phone5" />
</span></td>
</tr>
</table>
<p><span class="title">Registrant Agency Information</span>:</p>
<p align="left" class="style1"><strong>Agency Name*</strong>:
<input type="text" name="Agency" size="48" id="Agency" />
</p>
<p align="left" class="style1">Mailing Address:
<input type="text" name="Mailing" size="48" id="Mailing" />
</p>
<p align="left" class="style1">City:
<input type="text" name="City" size="48" id="City" />
Zip:
<input type="text" name="Zip" size="15" id="Zip" />
</p>
<p align="left" class="style1"><strong>Phone*</strong>:
<input name="AgencyPhone" type="text" id="AgencyPhone" size="48" />
</p>
<p align="center"><input type="submit" value="Submit" /></p>
</form>
我还有一组单选按钮(名为Rate)和复选框(名为Fee),我将其删除。一次有一个问题......
答案 0 :(得分:1)
NEW VERSION(编辑)
有一些错误。
事实上,Agency Phone: ".$AgencyPhone.";"
中的一个错位的分号应该读作Agency Phone: ".$AgencyPhone."";
,应该是在外面而不是被“夹在中”,就像它一样。当需要";"
"";
另一个错误是未定义email
变量。由于表单不包含名为“email”的输入字段,因此将if(isset($_POST['email'])) {
替换为if(isset($_POST['submit'])) {
还添加了foreach
来提升作品以定义每个表单的字段/变量。
<?php
if(isset($_POST['submit'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "c@d.com";
$email_subject = "Form Submitted";
$email_from = "c@d.com";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Agency']) ||
!isset($_POST['AgencyPhone'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Agency = $_POST['Agency']; // required
$AgencyPhone = $_POST['AgencyPhone']; // required
$contact = $_POST['contact']; // not required
$Zip = $_POST['Zip']; // not required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Agency)) {
$error_message .= 'The Agency Name you entered does not appear to be valid.<br />';
}
if(strlen($AgencyPhone) < 2) {
$error_message .= 'The Agency Phone you entered does not appear to be valid.<br />';
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
// This is where all the MAGIC happens
foreach ($_POST as $key=>$value) {
$email_message.=$key.": " . $value . "\n";
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if(mail($email_to, $email_subject, $email_message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
?>
<?php
}
?>
OLD VERSION
尝试一下:
<?php
// You may have to use "email" or "email_from" - comment one out.
// if(isset($_POST['email'])) {
if(isset($_POST['email_from'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "c@d.com";
$email_subject = "Form Submitted";
$email_from = "c@d.com";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Agency']) ||
!isset($_POST['AgencyPhone'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Agency = $_POST['Agency']; // required
$AgencyPhone = $_POST['AgencyPhone']; // required
$contact = $_POST['contact']; // not required
$Zip = $_POST['Zip']; // not required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Agency)) {
$error_message .= 'The Agency Name you entered does not appear to be valid.<br />';
}
if(strlen($AgencyPhone) < 2) {
$error_message .= 'The Agency Phone you entered does not appear to be valid.<br />';
}
// $email_message = "You received a message from your site!\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message="
Class: ".$contact."
Dates: ".$Dates." through ".$through."
Location: ".$Location."
Fee: ".$Fee.", ".$Rate."
Students:
1: ".$Last1.", ".$First1.", ".$Email1.", ".$Phone1."\n;
2: ".$Last2.", ".$First2.", ".$Email2.", ".$Phone2."\n;
3: ".$Last3.", ".$First3.", ".$Email3.", ".$Phone3."\n;
4: ".$Last4.", ".$First4.", ".$Email4.", ".$Phone4."\n;
5: ".$Last5.", ".$First5.", ".$Email5.", ".$Phone5."\n;
Agency: ".$Agency.";
Mailing: ".$Mailing.";
City: ".$City.";
Zip: ".$Zip.";
Agency Phone: ".$AgencyPhone."
";
// create email headers
// $headers = 'From: $email_from' ."\r\n" . 'Reply-To: $email_from' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$headers = 'MIME-Version: 1.0' . "\r\n";
// You can comment out the line below if sending an HTML based message
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
// Previous mail function with @ symbol
// @mail($email_to, $email_subject, $email_message, $headers);
// mail($email_to, $email_subject, $email_message, $headers);
if(mail($email_to, $email_subject, $email_message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
?>
<?php
}
?>