I would like to be able to send emails to everyone in my mysql database. As of now the code below will only send an email to the first row in my mysql table. The goal is to send one email to all the users in my database.
<?php
//Connect To Database
include "../connection_string.php";
mysql_connect($host,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($db_name);
$result = mysql_query("select property_notifications.email, crm.city, crm.state, crm.primary_fname, crm.primary_lname, crm.bedrooms, crm.baths, crm.assignee, userinfo.fname, userinfo.lname, userinfo.company, userinfo.homecontact, userinfo.clientid from inmobilmex_connect.property_notifications join inmobilmex_connect.crm on property_notifications.email=crm.primary_email join inmobilmex_connect.userinfo where property_notifications.sender=userinfo.clientid");
while($row = mysql_fetch_array($result)){
$recipients=$row['email'];
$prospect_city=$row['city'];
$prospect_state=$row['state'];
$prospect_fname=$row['primary_fname'];
$prospect_lname=$row['primary_lname'];
$bedrooms=$row['bedrooms'];
$baths=$row['baths'];
$realtor_assignee=$row['assignee'];
$fname=$row['fname'];
$lname=$row['lname'];
$company=$row['company'];
$homecontact=$row['homecontact'];
$clientid=$row['clientid'];
//sends email via CRON Jobs
$to = $recipients;
$headers .= 'From: INMOBILMEX <inmobilmex@inmobilmex.com>' . "\r\n";
$headers .= 'Reply-To: inmobilmex@inmobilmex.com'. "\r\n";
$subject = "INMOBILMEX - Nuevas propiedades disponibles en $prospect_city $prospect_state";
$body = "Hola $prospect_fname $prospect_lname,\n \nA continuacion aparece un enlace sobre las busquedas de propiedades que coinciden con su peticion. \n\n http://www.inmobilmex.com/home_search_results.php?optionsRadios=option1&state=&city=$prospect_city&bedrooms=$bedrooms&baths=$baths \n\nFavor de comunicarse conmigo si le interesa alguna propiedad.\n\nQuedo de usted,\n$fname $lname\n$company\n$homecontact\n$cellcontact\n$clientid";
mail($to, $subject, $body, $headers);
}
mysql_close();
?>
Any Help is appreciated!