websponge Posted August 19, 2010 Share Posted August 19, 2010 Hi, Im getting better at this php lark! ok so now I have a signup website page, all details get added to the database including an email address, all works fine. now I would like a page, with a simple text box, that when you hit submit, it send the contents of the text box to all email address` in the members table, a really really simple newsletter so to speak. Its purely for my learning curve and Ill set up recapacha on it anyway. but Im getting a bit lost in the code, could someone guide me please? I can grab the contents of the text box like this: $letter = $_POST['letter]; but how do I send to all recipients? $recipient = ("SELECT email FROM members"); thanks Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/ Share on other sites More sharing options...
ober Posted August 19, 2010 Share Posted August 19, 2010 Start with this: http://www.phpfreaks.com/forums/index.php/topic,95441.0.html And in the while loop, you need to do one of 2 things: 1) Add all users to an array or comma separated string to use in the mail() function 2) mail each recipient separately in the while loop. I would send one email to all recipients, personally... and make sure you BCC them. Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1101240 Share on other sites More sharing options...
websponge Posted August 19, 2010 Author Share Posted August 19, 2010 Quote Start with this: http://www.phpfreaks.com/forums/index.php/topic,95441.0.html And in the while loop, you need to do one of 2 things: 1) Add all users to an array or comma separated string to use in the mail() function 2) mail each recipient separately in the while loop. I would send one email to all recipients, personally... and make sure you BCC them. thanks, I can get all the email address to display, like the link you gave, thats not the problem, I need to do what you said, and send one email to all recipients with BCC but I dont know how.. thanks again Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1101248 Share on other sites More sharing options...
websponge Posted August 20, 2010 Author Share Posted August 20, 2010 anyone please? Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1101539 Share on other sites More sharing options...
websponge Posted August 21, 2010 Author Share Posted August 21, 2010 Gentle bump :'( Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102005 Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 Have you looked at the examples in the manual? mail Where exactly are you stuck? Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102009 Share on other sites More sharing options...
websponge Posted August 23, 2010 Author Share Posted August 23, 2010 Im just a bit stuck on what the code should be, I can select all emails from the member table, but dont know how to send an email to all of them? Thanks Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102612 Share on other sites More sharing options...
trq Posted August 23, 2010 Share Posted August 23, 2010 Just bcc them in. A simple example. <?php // this would come from your database. $users = array('foo@foo.com','bar@bar.com','boo@boo.com'); $to = 'you@youremailaddress.com'; $subject = 'subject'; $message = 'this is an example'; $headers = 'From: you@yourwebsite.com' . "\r\n" . 'Reply-To: you@yourwebsite.com' . "\r\n" . 'Bcc: ' . implode(', ', $users) . "\r\n"; 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> This will send the email to you, but bcc in all your users from your database. Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102615 Share on other sites More sharing options...
websponge Posted August 23, 2010 Author Share Posted August 23, 2010 right! ive never seen the "implode" command, this makes sense, thankyou, how would I get the emails into an array? I dont want to type them all out..? Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102617 Share on other sites More sharing options...
trq Posted August 23, 2010 Share Posted August 23, 2010 Quote how would I get the emails into an array? I dont want to type them all out..? if ($result = mysql_query("SELECT email FROM users")) { if (mysql_num_rows($result)) { $users = array(); while ($row = mysql_fetch_assoc($result)) { $users[] = $row['email']; } } } Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102620 Share on other sites More sharing options...
websponge Posted August 23, 2010 Author Share Posted August 23, 2010 Awesome! thankyou very much.. I get it! Link to comment https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/#findComment-1102657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.