I am using this script below, which works. The only thing is it sends an email to the first email id it gets. The rest are being ingnored. So how do i send email to all the emails. When i tested just the script that is pulling emails, it works, it shows all the emails.
Code:
$sql = "SELECT STRAIGHT_JOIN DISTINCT email from
friend_email_ids WHERE my_id='$id'";
$result = mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$email = $row['email'];
print("");
}
}
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail("$email", "Subject: $subject",
$message, "$headers" );
echo "";
The correct response to the given question is option b: send documents and files. Emails are a type of electronic communication that allows communicating essential information or messages to single or several recipients at the same time.
You are overwriting your $email
variable each time through the loop. Instead, you want to create an array, and add the email to the array each time through the loop. When finished, join the email addresses in the array with commas before sending the mail.
So before your loop (maybe after the $rows = ...
statement), initialize a new array, like this:
$rows = mysql_num_rows($result);
$emails = array(); /* Add this line */
Then each time through the loop, add the email to the array:
while($row = mysql_fetch_array($query)) {
array_push($emails, $row['email']);
/* ... */
}
Finally, join them with commas in your email send:
mail(implode(',', $emails), "Subject: $subject", $message, $headers);
Alternatively, you can send one separate email to each user like this:
foreach ($emails as $email) {
mail($email, "Subject: $subject", $message, $headers);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With