You know how to send 1 email and store emails in a mysql db, right?
I also suggest phpmailer() to send the emails. You can also use this to log all of the emails it fails to throw mail at, along with those that worked
Of course this is how to send the emails to all the users: (change the names accordingly)
PHP:
$query=mysql_query('SELECT `email`,`name` FROM `users`'); //grab emails and names from database
while($row = mysql_fetch_array($query)) //start a loop to send an email to each individual
{
//mail function with $row['email'] as the email address
//I'm using phpmailer as an example here - - >
include_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $message; //message inside the email
$mail->From = $from_email; //email address that the email is being sent from
$mail->FromName = "Your Company Name"; //more in depth for who the mail is from.
$mail->Subject = $subject; //The subject for the message
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($message_html); //HTML version of the message.
$mail->AddAddress($row['email'], $row['name']);
if(!$mail->Send()) {
echo '<p>Mailer Error: ' . $mail->ErrorInfo .'</p>';
} else {
echo '<p>Message sent to: '.$row['name'].' at their email address: '.$row['email'].'!</p>';
}
}
That should work to send the email. You just need to fill in all the blanks:
$row['name'] and $row['email'] need to apply to your MySQL DB.
$message, $from_email, $subject, and $message_html need to apply to the email your sending.
Your Company Name needs to apply to you as well.
That's it. Hope this helps.
Oh yeah, don't forget to download phpmailer and upload it to your host. After that, the include should link up fine and it should work. If not, you'll get an error that'll help you out (hopefully)