unless you use some kind of wierd javascript funtionality to submit all forms (or get more complex to send just the email ones), I sugest you encapsulate all the boxes in one form (as they are being send at the same time anyway.) I spent a few minutes and wrote an example to illustrate:
$keysearch = "email_"; //we'll single out the email_* input names.
$subject = "Your Global Subject";
$from = "youremail@yoursite.com";
$message = "Possibly you have a global message too??";
if (isset($_POST['Submit'])) {
foreach ($_POST as $postkey => $email) {
if (substr($postkey, 0, strlen($keysearch)) == $keysearch) {
$number = substr(strrchr($postkey, "_"), 1);
$to = "{$_POST['name_'.$number]} <$email>";
send_mail($to, $from, $subject, $message);
}
}
}
/*
I find it easier sometimes to encapsulate the
mail function in my own function in case I want to later
change the headers, etc. I usually reuse this function
in a script or group of scripts which means this function
is typically part of a class or an include file. A bit of
overkill for this example though ;-)
*/
function send_mail($to, $from, $subject, $message)
{
$headers = "From: $from\r\n";
$headers .= "Reply-To: $from\r\n";
mail($to, $subject, $message, $headers);
}
//HTML code below...
<form name="form1" method="post" action="[PHP_TAG]php echo $_SERVER['PHP_SELF'][PHP_CLOSE_TAG]">
<table width="200" border="0">
<tr>
<td width="95">Name</td>
<td width="95">Email</td>
</tr>
<tr>
<td><input name="name_1" type="text" id="name_1"></td>
<td><input name="email_1" type="text" id="email_1"></td>
</tr>
<tr align="center">
<td><input name="name_2" type="text" id="name_2"></td>
<td><input name="email_2" type="text" id="email_2"></td>
</tr>
<tr align="center">
<td><input name="name_3" type="text" id="name_3"></td>
<td><input name="email_3" type="text" id="email_3"></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
P.S. Don't let the
="[PHP_TAG]php echo $_SERVER['PHP_SELF'][PHP_CLOSE_TAG]">
confuse you, I just put it in so the code highlighting would work properly.