woolyg Posted September 22, 2007 Share Posted September 22, 2007 Hi all, I'm populating a field in MYSQL that collects email addresses for a certain topic and saves them like this: mail1@mail.com|emailaddress2@mail.com|email3@email.com - Basically what I'd like to do is explode the data, and set up a mailer from PHP that informs each of the addresses individually that there has been an update to the topic. I *don't* want each of the mail addresses to be visible to all the recipients on the list, so simply inserting the data into the TO: field won't do, because then all the addresses are visible, causing security concerns. I tried doing this: <?php //Send a mail to the mailing list $get_mailing_list = mysql_query("SELECT mailing_list FROM table WHERE post_id='$post_id'"); $runget_mailing_list = mysql_fetch_assoc($get_mailing_list); $mailing_list = $runget_mailing_list['mailing_list']; while($rad=explode('|',$mailing_list)){ $reciever=$rad['mailing_list']; $subject = " Reply to a posting"; $message = " A reply has been posted to a posting you are tracking. Have a look here : [url of reply] No need to reply to this email. Thanks! "; $from = "myemail@site.com"; $headers = "From: $from"; mail($reciever,$subject,$message,$headers); } ?> ..but something happened server-side when it tried to carry out the command and brought the CPU usage up to 100%. Has anyone done this before, or could you give me any pointers? All info appreciated. Woolyg. Quote Link to comment https://forums.phpfreaks.com/topic/70289-mail-a-set-of-addresses-from-a-mysql-result/ Share on other sites More sharing options...
JJohnsenDK Posted September 22, 2007 Share Posted September 22, 2007 you cant just run a loop like that... a loop have to have an end ohterwise it will never stop and therefore your CPU goes crazy... also if you are storing the mails in a database anyways, then do it like this instead: mail_id - 1 - mail: test@test.com mail_id - 2 - mail: test@test.com mail_id - 3 - mail: test@test.com mail_id - 4 - mail: test@test.com and so on... then you can do a loop on your query for that mail table.. Quote Link to comment https://forums.phpfreaks.com/topic/70289-mail-a-set-of-addresses-from-a-mysql-result/#findComment-353077 Share on other sites More sharing options...
woolyg Posted September 23, 2007 Author Share Posted September 23, 2007 OK, thanks for letting me know about the CPU usage! I don't fully understand what you mean to do with the information - do you mean to create new fields for mail_id1, mail_id2 etc? That will not work, as it's not known how many mail addresses will be added to the list, it could be 1, it could be 100.. How do you reckon I should do it? Thanks for your input so far.. Cheers, Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/70289-mail-a-set-of-addresses-from-a-mysql-result/#findComment-353116 Share on other sites More sharing options...
eldorik Posted September 23, 2007 Share Posted September 23, 2007 I think this will work. <?php $get_mail_address = mysql_query("SELECT mailing_list FROM table_name WHERE post_id = '$post_id'"); $row_mail_addresses = mysql_fetch_assoc($get_mail_address); $number_rows = mysql_num_rows($get_mail_address); if($number_rows > 0) { $mail_address = explode('|', $row_mail_addresses['mailing_list']); foreach($mail_address as $address) { $subject = " Reply to a posting"; $message = " A reply has been posted to a posting you are tracking. Have a look here : [url of reply] No need to reply to this email. Thanks! "; $from = "myemail@site.com"; $headers = "From: $from"; mail($address, $subject, $message, $headers); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70289-mail-a-set-of-addresses-from-a-mysql-result/#findComment-353256 Share on other sites More sharing options...
woolyg Posted September 23, 2007 Author Share Posted September 23, 2007 eldorik - perfect! Thanks so much. Woolyg. Quote Link to comment https://forums.phpfreaks.com/topic/70289-mail-a-set-of-addresses-from-a-mysql-result/#findComment-353262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.