I have no idea if it sent one email, half of the emails or all of them. I dont want to try it again until I know for sure that I am doing it in a way that will work (I dont want all of my users to get 5 emails while I play around with settings).
Am I even right to put this script into a page? Or should it be a file that is run on the server...and if so, how would I do that?
Here's my script:
Code: Select all
<?php
session_start();
include( log into the database );
$query = "select distinct email from users";
$result = mysql_query($query);
while ( $line = mysql_fetch_row($result) )
{
mail($line[0], $subject, $body, "From: myemail@mysite.com");
}
$result = mysql_query($query);
echo "The emails have been sent to: <br>";
$num_sent = mysql_num_rows($result);
echo "$num_sent email addresses<br><br>";
while ( $line = mysql_fetch_row($result) )
{
echo "$line[0]<br>";
}
?>