ajsuk Posted January 11, 2007 Share Posted January 11, 2007 Hey there, another nooby question I'm sure but again I'm stuck so I shall have to ask. ;)As the title says really, I'm looking to grab email addresses from a database to make up a recipients list for this email script...I've got this which does the job but having a script run 500 times over sending emails doesn't sound the best of ideas...[code]<db connect code etc...>while($row = mysql_fetch_array($result)){$to = $row['email'];$subject = "Test Email";$message = "Test Email Message";$from = "[email protected]";$headers = "From: $from";mail($to,$subject,$message,$headers);}mysql_close($con);?>[/code]Is there some way I can store the results in a variable to be used as the mail-to value for sending to all at once rather than one by one?Thanks for any help you can give! :) Link to comment https://forums.phpfreaks.com/topic/33795-pulling-email-addresses-from-db-and-mailing-to-them/ Share on other sites More sharing options...
Draicone Posted January 11, 2007 Share Posted January 11, 2007 Try this:[code]<?php// <db connect code etc...>while($row = mysql_fetch_array($result)){$mailto[] = array("to"=>$row['email'], "subject"=>"Test email", "message"=>"Test email message", "from"=>"[email protected]", "headers"=>"From: $from");}mysql_close($con);foreach($mailto as $mail) mail($mail['to'],$mail['subject'],$mail['message'],$mail['headers']);?>[/code]Hope this helps. Link to comment https://forums.phpfreaks.com/topic/33795-pulling-email-addresses-from-db-and-mailing-to-them/#findComment-158715 Share on other sites More sharing options...
ajsuk Posted January 16, 2007 Author Share Posted January 16, 2007 Sorry for the delay, life got busy. Anyway, this didn't seem to work unfortunatly. :(Anything else I can do? :-\ Link to comment https://forums.phpfreaks.com/topic/33795-pulling-email-addresses-from-db-and-mailing-to-them/#findComment-161946 Share on other sites More sharing options...
ajsuk Posted January 19, 2007 Author Share Posted January 19, 2007 *bump* :) Link to comment https://forums.phpfreaks.com/topic/33795-pulling-email-addresses-from-db-and-mailing-to-them/#findComment-164124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.