1

私は主に、複数の名前と電子メールアドレスを処理できるフォームを持っています。この他のPHPファイルは、mail()を使用してこれらの電子メールに送信するようにフォームを処理します。フォームでループを使用して、入力フィールドが複数のエントリに繰り返されてから送信されるようにしました。したがって、フォームは次のようになります。

<?php for ($i = 1; $i <= 10; $i++) { ?> // here's the PHP loop

<input type="text" 
  id="<?php echo 'firstname'.$i ?>" name="<?php echo 'firstname'.$i; ?>"
  value="<?php echo $_GET['firstname']; ?>" />  
      value?
<br/>
<input type="text" id="<?php echo 'lastname'.$i; ?>" 
  name="<?php echo 'lastname'.$i; ?>" 
  value="<?php echo $_GET['lastname']; ?>" />

<input type="text" id="<?php echo 'email'.$i; ?>" 
  name="<?php echo 'email'.$i; ?>" 
  value="<?php echo $_GET['email']; ?>"/>
<?php } ?> // END of loop

<input class="button" type="submit" value="Submit" name="submit" />

そのため、上記を処理するための2番目のPHPファイルで2回混乱しています。上記の入力フィールドの値を使用して、電子メールごとにメッセージをエコーするにはどうすればよいですか。入力された値が配列にあるため、explodeを使用するかどうかわかりませんか?つまり、各メールには個別にメッセージを送信する必要があります。

extract($_GET, EXTR_PREFIX_SAME, "get");

#construct email message
$email_message = "Name: ".$firstname." ".$lastname."
Email: ".$email;


#construct the email headers
$to = "email something";
$from = $_GET['email'];
$email_subject = "Registration Details";

#now mail
mail($to, $email_subject, $email_message, "From: ".$from);


echo "<b>Thank you ".$firstname." ".$lastname."! You are now registered.</b><br/><br/>";
echo "Here's your registration information:<br/><br/>";

echo "Email: ".$email."<br/>";
4

2 に答える 2

1

概念は次のとおりです。値を保持するために配列を使用して入力フォームに名前を付ける必要があるため、メッセージを個別に送信できます。したがって、次のような入力フォームがあります。

for($i = 1; $i <= 10; $i++)
{
<input name="txtname[$i]">
<input name="txtnickname[$i]">
<input name="txtemail[$i]">
}

PHPコードで、上記のフォームを次のように処理します。

   for($i = 1; $i <= 10; $i++)
   {
       mail($_POST['txtemail'][$i], 'Thx' . 
            $_POST['txtnickname'][$i], 'Body' . $_POST['txtname'][$i]
   }

それがうまくいくかどうか私に知らせてください!

于 2013-03-26T04:55:39.687 に答える
0

1つの非表示フィールド名カウントを取得し、その中の反復の総数を値として渡してください。

<?php
extract($_GET, EXTR_PREFIX_SAME, "get");
for($i=0;$i<$count;$i++){
#construct email message
$email_message = "Name: ".$firstname.$i." ".$lastname$i."
Email: ".$email.$i;


#construct the email headers
$to = "email something";
$from = $email.$i;
$email_subject = "Registration Details";

#now mail
mail($to, $email_subject, $email_message, "From: ".$from);


echo "<b>Thank you ".$firstname.$i." ".$lastname.$i."! You are now registered.</b><br/><br/>";
echo "Here's your registration information:<br/><br/>";

echo "Email: ".$email.$i."<br/>";
}
?>
于 2013-03-26T04:45:24.880 に答える