Zergman Posted August 31, 2010 Share Posted August 31, 2010 So this is probably very simple, but I can't get it. Trying to send 1 email to a list of addresses from a mysql query. pcontact is the email addresses, here's the query to get them $query_rsFind = " SELECT pcontact FROM user_logins WHERE (pcontact_type = 'SMS' OR pcontact_type = 'Email') AND pcontact_active = '1' AND active = '1' "; $rsFind = mysql_query($query_rsFind, $cnepix) or die(mysql_error()); $row_rsFind = mysql_fetch_array($rsFind); What i'm trying to do is put these addresses into 1 variable to send separated by commas like user1@gmail.com, user2@company.com, user3@xcompany.com So ultimately, want this mail($sendTo, $subject, $body); Arg, hard to get across what I can't get. Basically want the results from my query to do this $sendTo = user1@gmail.com, user2@company.com, user3@xcompany.com Link to comment https://forums.phpfreaks.com/topic/212159-php-email-help/ Share on other sites More sharing options...
freelance84 Posted August 31, 2010 Share Posted August 31, 2010 $query = mysql_query("SELECT all the results in the MySQL query. Then you could use, $rows = mysql_num_rows($query) This will tell you the number of results found. Then you could run a for loop: for($i=0;$i<$rows;++$i) { $row = mysql_fetch_row($query); //this will take one row of results from the query //then do any mailing you wish to do on the returned row (in this case $row[0] as your first result back should be the emails) } //Once the loop has reached the end it will have taken and used all the results fround from you query For multiple emails you are advised to use php mailer though Link to comment https://forums.phpfreaks.com/topic/212159-php-email-help/#findComment-1105534 Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 Something like this should give you the recipient string you're looking for, assuming pcontact is a field that holds email addresses: // Set the SQL (include WHERE conditions) $result = mysql_query('SELECT pcontact FROM user_logins'); // Initialize the array that holds the recipients $recipients = array(); // Iterate over each email address result while ($row = mysql_fetch_assoc($result)) { // Store each email address result in the recipient array $recipients[] = $row['pcontact']; } // while() // Turn the array into a string separated by commas $recipients = implode(', ',$recipients); // "mike@gmail.com, tommy@yahoo.com, bob@hotmail.com" Link to comment https://forums.phpfreaks.com/topic/212159-php-email-help/#findComment-1105535 Share on other sites More sharing options...
Zergman Posted September 3, 2010 Author Share Posted September 3, 2010 Quote Something like this should give you the recipient string you're looking for, assuming pcontact is a field that holds email addresses: // Set the SQL (include WHERE conditions) $result = mysql_query('SELECT pcontact FROM user_logins'); // Initialize the array that holds the recipients $recipients = array(); // Iterate over each email address result while ($row = mysql_fetch_assoc($result)) { // Store each email address result in the recipient array $recipients[] = $row['pcontact']; } // while() // Turn the array into a string separated by commas $recipients = implode(', ',$recipients); // "mike@gmail.com, tommy@yahoo.com, bob@hotmail.com" Worked great, tanks a million! Link to comment https://forums.phpfreaks.com/topic/212159-php-email-help/#findComment-1106689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.