Sounds simple. However I'm stuck on how to build my loop.
would I use
Code: Select all
$array = ('$email1','$email2','$email3','etc..');
foreach ($array as $email)
{
mail();
}Moderator: General Moderators
Code: Select all
$array = ('$email1','$email2','$email3','etc..');
foreach ($array as $email)
{
mail();
}Code: Select all
$allemails = array('$email1','$email2','$email3','$email4','$email5','$email6','$email7','$email8','$email9','$email10');
// above lets say email 6-10 is empty, then I do this
foreach($allemails as $email)
{
mail();
}
// what would happen?Code: Select all
$array = array_filter('strlen', $array);Code: Select all
if($_POST['action'] == "invitefriends")
{
if(!isset($_COOKIE['username']))
{
header("Location: login.php");
}
$email1 = mysql_real_escape_string(strip_tags($_POST['email1']));
$email2 = mysql_real_escape_string(strip_tags($_POST['email2']));
$email3 = mysql_real_escape_string(strip_tags($_POST['email3']));
$email4 = mysql_real_escape_string(strip_tags($_POST['email4']));
$email5 = mysql_real_escape_string(strip_tags($_POST['email5']));
$email6 = mysql_real_escape_string(strip_tags($_POST['email6']));
$email7 = mysql_real_escape_string(strip_tags($_POST['email7']));
$email8 = mysql_real_escape_string(strip_tags($_POST['email8']));
$email9 = mysql_real_escape_string(strip_tags($_POST['email9']));
$email10 = mysql_real_escape_string(strip_tags($_POST['email10']));
$message = mysql_real_escape_string(htmlentities($_POST['message'],ENT_QUOTES));
if(!($email1 && $email2 && $email3 && $email4 && $email5 && $email6 && $email7 && $email8 && $email9 && $email10))
{
header("Location: invitefriends.php?error=1");
die();
}
if(!$message)
{
header("Location: invitefriends.php?error=2");
die();
}
$array = array('$email1','$email2','$email3','$email4','$email5','$email6','$email7','$email8','$email9','$email10');
foreach($array as $email)
{
if($email != '')
{
$recipient = $email;
$subject = "An invitation to join ShowMyPro.com";
$body = "email body";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"Show My Pro.com\" <register@showmypro.com>\n";
mail($recipient,$subject,$body,$headers);
}
}
}Code: Select all
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />
<input type="text" id ="email[]" name="email[]" />Code: Select all
$array = $_POST['email'];
// The following line makes sure 10 emails aren't sent unless 10 emails are entered
$array = array_filter('strlen', $array);
$count = count($email);
// The following is optional
if ($count > 10) {
// someone tampered with your form
}
// This will make sure that at least one email was entered
if ($count==0) {
// error handler, no email was entered
}
foreach ($array as $email) {
mail($recipient, $whatever, $whatever);
}