Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从html表单收集数据的PHP脚本_Php_Forms - Fatal编程技术网

从html表单收集数据的PHP脚本

从html表单收集数据的PHP脚本,php,forms,Php,Forms,我编写了一个php脚本,用于从html表单收集表单数据。下面是代码。我认为这是我缺少的简单的东西,我的php经验是有限的 欢迎提供任何帮助/建议。如果您编辑代码,请尽量具体,以便我可以看到错误所在 "\nComments:\n".$comments. ; <?php $error = "\n Please review the information you provided, there seems to be a problem" ; $email1 = 'root@centos6.l

我编写了一个php脚本,用于从html表单收集表单数据。下面是代码。我认为这是我缺少的简单的东西,我的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……的开头添加print,则电子邮件正文为空。。。。。。。然后我可以看到收集的示例数据,但我得到的是:Date:Thu,2012年4月19日15:54:22+0100 IST From:Apache To:root@centos6.labform.localdomain主题:root@centos6.labform.localdomain实验室系统申请表来源:且未收集其他数据

以下是html表单: 下面是collection.php:

邮件函数中的参数顺序错误。发件人地址应位于标题中。看看能不能搞定它。

安东尼奥

您需要更详细地描述出现了什么问题,以及我们需要查看表单的所有代码,尽管听起来脚本正在运行

在Lex所说的基础上,$body变量有一个。最后是不应该出现的情况:

$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.
"\nComments:\n".$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.
"\nComments:\n".$comments ;

您看到了什么错误消息,或者您期望的是什么/没有发生?正如Richard指出的,这将由于语法错误而失败。这是一个好主意,检查一些至少运行前张贴!我认为指定该字符串的更好方法是只使用一个开始和结束分隔符,并按字面意思将其放在换行符中。这样就省去了大量的开/关和连接。哈弗,这就是您的意思:$body=我们从.$name收到了以下信息:$n\n详情如下:\n\nFirstName:\n$firstname\nLastName:\n$lastname\nExtNumber:\n$extnumber\n部门:\n$department\nEmail:\n$email\nFormFactor:\n$type\n系统类型:\n$systems\n注释:\n$comments;现在几乎所有工作都已删除:$message=$body,并已更改$body=。。。。。。至$message=。。。。。。现在,所有表单数据都已收集,但“$from”显示为空白。是否有任何建议?谢谢,$email变量有数据吗?