私はその入力が電子メールで送信されるようにするプログレッシブシーケンスでユーザー入力を取得しようとしています。電子メールでの送信は、私がまだ取り組んでいない全く別の問題です。 私が問題を抱えているのは、ユーザーが「メールを送信しますか? (はい/いいえ)ラジオボタンでは、その質問の入力が正しく処理されません。 フォームアクションとして別のPHPファイルを使用しても、emailName、emailAddress、およびemailMsgに関連したエラー( "Notice:Undefined index ...")がまだ残っています。 さらに、$ _POST [athletes]配列をさらに使用する必要がありますが、その時点で可変スコープの外にあると思います。 これをすべてまとめておきたいのですが、私は実際にいくつかの質問をしています:
1)すべてのフォームを同じファイルで一緒に使うにはどうしたらいいですか?
2)プログラムが実際に「メールを送信しますか?ラジオボタンを使用してフォームアクションとして別のPHPファイルを使用すると、なぜ定義されていないインデックスエラーが発生するのですか?
3)アスリート[]アレイをコード内でさらに使用しようとすると、エラーが発生するのはなぜですか?何とか配列の値をコードのその部分に渡す必要がありますか?
正確であるユーザーが問題を取得するのにかかる手順:
は、1つの以上のアスリートのチェックボックスを選択し、「表示選択(S)」ボタンをクリックしてください。
「メールを送信しますか?」を選択します。 [送信]ボタンをクリックします。
何らかの理由でコードを再起動します。
ご協力いただければ幸いです。また、これは私の最初の投稿ですので、申し訳ありませんが、私は質問に間違っているかどうか、サイトのエチケットに応じていません。 長いコードの断片についてもお詫びしますが、どの部分がこれを間違っているのかわかりません。
<b><h1><center>Athelete Selection Screen</center></h1></b>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<p>
<fieldset>
<legend>Athletes Available: </legend>
<input type="checkbox" id="student1"
name="athletes[]" value="Student1 Test">
<label for="student1">Student1 Test</label><br/>
<font color="grey">Football - Running back</font><br/>
<p>
<input type="checkbox" id="student2"
name="athletes[]" value="Student2 Test">
<label for="student1">Student2 Test</label><br/>
<font color="grey">Soccer - Left Forward</font><br/>
</p>
<p>
<input type="checkbox" id="student3"
name="athletes[]" value="Student3 Test">
<label for="student1">Student3 Test</label><br/>
<font color="grey">Baseball - Pitcher/Left Outfield</font><br/>
</p>
</fieldset>
<p>
<?php echo("\t\t\t\t\t"); ?><button type="submit" name="submit" value="submit">Display Selection(s)</button>
</p>
</form>
<fieldset>
<legend>Athletes You Selected: </legend>
<?php
if (!empty($_POST['athletes']))
{
echo "<ul>";
foreach($_POST['athletes'] as $value)
{
echo "<li>$value</li>";
}
echo "</ul>";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<p>
<fieldset>
<legend>Send Email? </legend>
<input type="radio" id="Yes"
name="radioSendMsg[]" value="Yes">
<label for="student1">Yes</label>
<p>
<input type="radio" id="No"
name="radioSendMsg[]" value="No">
<label for="student1">No</label><br/>
</p>
<button type="submit" name="submitRadio" value="submit">Submit</button>
</p>
</form>
<?php
if (!empty($_POST['radioSendMsg']))
{
foreach($_POST['radioSendMsg'] as $radioMsg)
{
if($radioMsg == "Yes")
{
echo "\tPlease enter information regarding the email to be sent: ";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<p>
<label for="emailName"> Name: </label><br/>
<input type="text" size="25" id="emailName" name="emailName" />
</p>
<p>
<label for="emailAddress">E-mail Address: </label></br>
<input type="text" size="25" id="emailAddress" name="emailAddress" />
</p>
<p>
<textarea id="emailMsg" name="emailMsg" cols="30" rows="5"></textarea>
</p>
<button type="submit" name="emailSubmit" value="send">Send Message</button>
</form>
<?php
$msg = "Name: ".$_POST['emailName']."\n";
$msg.= "E-Mail: ".$_POST['emailAddress']."\n";
$msg.= "Message: ".$_POST['emailMsg']."\n";
$msg.= "<ul>";
foreach($_POST['athletes'] as $value)
{
$msg.= "<li>$value</li>\n";
}
$msg.= "</ul>";
$emailRecipient = "[email protected]";
$emailSubject = "Athlete Selection Submission";
$emailHeaders = "From: Sebastien\n"."Reply-To: ".$_POST['emailAddress'];
mail($emailRecipient,$emailSubject,$msg,$emailHeaders);
echo "Message sent: \n".$msg;
}
else
{
?> <p /> <?php
echo "\n\nNo email will be sent for your last athlete selection.";
?>
<br/>Please click <a href="http://localhost/CheckFormTest.html">here</a>
to return to the Athlete selection screen.
<?php
}
}
}
}
FYI:[PHP_SELF and XSS](http://stackoverflow.com/questions/6080022/php-self-and-xss)ソースのうち、それはページ上の唯一のXSS脆弱なコードではありません。あなたにもメールヘッダーインジェクションの脆弱性があるように見えます。[PHPでのメールインジェクションの適切な防止](http://stackoverflow.com/questions/11952473/proper-prevention-of-mail-injection-in-php) –
3つではなく1つの形式ですか? –
@ AlexanderO'Maraセキュリティの脆弱性に関する情報をありがとう。正直であるとは考えていなかった。 – Sebastien