-1

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そしてデータを逆の順序で収集してくれてありがとう!stonith

こんにちは、返信ありがとうございます。コードを編集しました。私はあなたの提案を追加しました。コードは正常に実行され、thankyou.htmlにリダイレクトされますが、各先頭にprintを追加すると、電子メールの本文は空になります: "\ 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/

4

2 に答える 2

1

アントニオ

すべてのコードに加えて何が問題なのかをもっと詳しく説明する必要があります (フォームを確認する必要があります)。ただし、スクリプトが実行されているように聞こえます。

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 ;
于 2012-04-19T12:46:31.707 に答える
1

関数内の引数のmail()順序が間違っています。送信元アドレスはヘッダーにある必要があります。この機能のマニュアルを見て、正しく理解してください。

于 2012-04-19T12:41:35.087 に答える