jmcc Posted September 23, 2009 Share Posted September 23, 2009 Then I use the while look in my code no emails are sent, but when I take it out only one is sent. Are there any other ways that I loop through the recordset to send email to everyone. Please help Here's the code: elseif ( $to == "Buyers") { mysql_select_db($database_prop, $prop); $query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'"); $dist = mysql_query($query_dist, $prop) or die(mysql_error()); $row_dist = mysql_fetch_assoc($dist); $totalRows_dist = mysql_num_rows($dist); // ---------------- SEND MAIL FORM ---------------- if($totalRows_dist > 0) { $count = 0; while ($rows_dist = mysql_fetch_assoc($dist)) { echo $row_dist['email']; // send e-mail to ... $to2 = $row_dist['email'] . ', '; echo $to2; // Your subject $subject="Property Distribution"; // From $header="from: Property Networking Solutions"; // Your message $messages= "Match alert notification\t\n\t\nThis property was sent to you by Property Networking Solutions.\t\n\t\nProperty Description:\t\nType: $proptype\t\nProvince: $propprov\t\nCity: $propcit\t\nSuburb: $propsub\t\nPrice: R $propprice\t\n\t\nHere is a link to the property: http://www.propertyforsalesa.co.za/buyer_detail_view.php?id=$propid\t\n\t\n\t\n" ; // send email $sentmail = mail($to2,$subject,$messages,$header); $count++; } } } Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/ Share on other sites More sharing options...
KevinM1 Posted September 23, 2009 Share Posted September 23, 2009 1. Where's your while-loop? 2. Use code tags. Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/#findComment-923431 Share on other sites More sharing options...
gevans Posted September 23, 2009 Share Posted September 23, 2009 have a look at the changes bellow and try it; elseif($to == "Buyers") { mysql_select_db($database_prop, $prop); $query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'"); $dist = mysql_query($query_dist, $prop) or die(mysql_error()); $totalRows_dist = mysql_num_rows($dist); if($totalRows_dist > 0) { while($rows_dist = mysql_fetch_assoc($dist)) { echo $row_dist['email']; // send e-mail to ... $to2 = $row_dist['email']; echo $to2; // Your subject $subject="Property Distribution"; // From $header="from: Property Networking Solutions"; // Your message $messages= "Match alert notification This property was sent to you by Property Networking Solutions. Property Description: Type: $proptype Province: $propprov City: $propcit Suburb: $propsub Price: R $propprice Here is a link to the property: http://www.propertyforsalesa.co.za/buyer_detail_view.php?id=$propid " ; // send email if(mail($to2,$subject,$messages,$header)) { echo 'mail sent to '.$to2; } else { echo 'mail not sent to '.$to2; } } } } Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/#findComment-923432 Share on other sites More sharing options...
jmcc Posted September 23, 2009 Author Share Posted September 23, 2009 I put the while in bold. Here's the code: <?php> elseif ( $to == "Buyers") { mysql_select_db($database_prop, $prop); $query_dist = ("SELECT DISTINCT email FROM private_buyer WHERE notify = '1' AND province = '$provDis' AND city = '$cityDis'"); $dist = mysql_query($query_dist, $prop) or die(mysql_error()); $row_dist = mysql_fetch_assoc($dist); $totalRows_dist = mysql_num_rows($dist); // ---------------- SEND MAIL FORM ---------------- if($totalRows_dist > 0) { $count = 0; while ($rows_dist = mysql_fetch_assoc($dist)) { echo $row_dist['email']; // send e-mail to ... $to2 = $row_dist['email'] . ', '; echo $to2; // Your subject $subject="Property Distribution"; // From $header="from: Property Networking Solutions"; // Your message $messages= "Match alert notification\t\n\t\nThis property was sent to you by Property Networking Solutions.\t\n\t\nProperty Description:\t\nType: $proptype\t\nProvince: $propprov\t\nCity: $propcit\t\nSuburb: $propsub\t\nPrice: R $propprice\t\n\t\nHere is a link to the property: http://page.php?id=$propid\t\n\t\n\t\n" ; // send email $sentmail = mail($to2,$subject,$messages,$header); $count++; } } } <?> Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/#findComment-923434 Share on other sites More sharing options...
jmcc Posted September 23, 2009 Author Share Posted September 23, 2009 I tried the code and the and this is what I get mail not sent to but i received a php mail error on my server which has not smtp setup right now. so it looks like it tried to send the email Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/#findComment-923438 Share on other sites More sharing options...
TeNDoLLA Posted September 23, 2009 Share Posted September 23, 2009 Well you need a smtp server on your system if you want to send mails at all. Link to comment https://forums.phpfreaks.com/topic/175205-problem-with-while-loop/#findComment-923449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.