我在编写用于从 html 表单收集表单数据的 php 脚本时遇到问题,下面是代码。我认为我缺少一些简单的东西,我的 php 经验是有限的。
任何帮助/建议表示赞赏。如果您编辑代码,请尝试具体说明,以便我可以看到错误在哪里。
"\nComments:\n".$comments. ;
<?php
$error = "\n Please review the information you provided, there seems to be a problem" ;
$email1 = 'root@centos6.labform.localdomain' ;
$to = "$email1";
$from = $_POST['email'];
$name = "$firstname $lastname";
$headers = "From: $email \n";
$subject = 'Lab Systems Request Form';
// we now create the email
$message = array();
$firstname = $_POST['firstname'] ;
$lastname = $_POST['lastname'] ;
$extnumber = $_POST['extnumber'] ;
$department = $_POST['department'] ;
$email = $_POST['email'] ;
$type = $_POST['type'] ;
$systems = $_POST['systems'] ;
$comments = $_POST['comments'] ;
$body = "We have received the following information from $name:\n\nHere are the details:\n"
"\nFirstName:\n".$firstname.
"\nLastName:\n".$lastname.
"\nExtNumber:\n".$extnumber.
"\nDepartment:\n".$department.
"\nEmail:\n".$email.
"\nFormFactor:\n".$type.
"\nSystemType:\n".$systems.
//$body ="We have received the following information from $name:\n\n";
//"Here are the details:\n " ;
//"FirstName: $firstname \n" ;
//"LastName: $lastname \n" ;
//"ExtNumber: $extnumber \n" ;
//"Department: $department \n" ;
//"Email: $email \n" ;
//"FormFactor: $type \n" ;
//"SystemType: $systems \n" ;
//"Comments: $comments \n" ;
// now we send the email and redirect to thankyou.html if all ok
$send = mail( $to,$from,$headers,$subject,$body );
//print "$to,$subject,$body,$headers";
if($send)
{header( "Location: thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify directly
$email1 or $email2"; }
?>
此外,当我出于某种原因设法打印所有数据时,它会在每行前面放置一个“1”:-S 并以相反的顺序收集数据,非常感谢!斯托尼斯
您好,感谢您的回复。我已经编辑了代码。我添加了你的建议。代码运行正常,它重定向到thankyou.html,但电子邮件正文为空,如果我在每个开头添加打印:“\nFirstName:\n”.$firstname。.......然后我可以看到示例数据已收集,但我得到的只是:日期:2012 年 4 月 19 日星期四 15:54:22 +0100 (IST) 来自:Apache 至:root@centos6.labform。 localdomain 主题:root@centos6.labform.localdomain 实验室系统申请表来自:并且没有收集其他数据
这是html表单: http ://dpaste.com/734277/ 这里是collection.php: http ://dpaste.com/734276/