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" />

所以现在我对处理上述内容的第二个 PHP 文件感到两次困惑。我如何在每封电子邮件中回显一条消息,但使用上面输入字段中的值。我不确定我是否使用爆炸,因为输入的值在数组中?换句话说,每封电子邮件都必须分别向它们发送一条消息。

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

请取一个隐藏字段名称计数,并将其中的迭代总数作为值传递。

<?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 回答