samoi Posted December 11, 2008 Share Posted December 11, 2008 hello guys, I have a database, and it contains users with emails and other stuff. I need to send them emails by the updates in my site, can I? I don't want to send them one by one, I want to send them all in once! should I use something like, <?php $users = "SELECT email FROM tableusers"; $SQL_users = mysql_query($users); $send = mail($users, "subject", "email message"); if ($send) { while ($me = mysql_fetch_assoc($send)) { echo $me['username']; echo "-----"; echo $me['email']; echo "---- Has been contacted"; } } else { echo "Failed"; } ?> I just made up this code right now, to be able to delevier my question ! Thank you in advance ! Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/ Share on other sites More sharing options...
Maq Posted December 11, 2008 Share Posted December 11, 2008 Why not loop through a select statement? $users = "SELECT email FROM tableusers"; $SQL_users = mysql_query($users); while($row = mysql_fetch_array($SQL_users)) { mail({$row['email']}, "subject" , "email message"); } Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-713063 Share on other sites More sharing options...
rtadams89 Posted December 11, 2008 Share Posted December 11, 2008 The "$users" variable needs to be a comma separate list of email addresses. Such as "a@a.com, b@b.com, c@c.com". Here is the function I use to retrieve email addresses from my database and turn them into a coma separated list: function calendar_mail() { //Database connection $conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Error connecting to mysql'); mysql_select_db(DB_NAME); $sql = 'SELECT user_email FROM phpbb_users WHERE user_notify_calendar="1" AND user_email!=""'; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $recepients = $recepients.$row['user_email'] . ", "; } $recepients = rtrim($recepients, " ,"); return $recepients; } The examples on the php website are also very helpful: http://us.php.net/function.mail Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-713065 Share on other sites More sharing options...
waynew Posted December 11, 2008 Share Posted December 11, 2008 Do your users want you to basically give out their emal addresses to other users? Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-713067 Share on other sites More sharing options...
samoi Posted December 12, 2008 Author Share Posted December 12, 2008 Why not loop through a select statement? $users = "SELECT email FROM tableusers"; $SQL_users = mysql_query($users); while($row = mysql_fetch_array($SQL_users)) { mail({$row['email']}, "subject" , "email message"); } thank you for your help, I found a tutorial ! Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-714105 Share on other sites More sharing options...
samoi Posted December 12, 2008 Author Share Posted December 12, 2008 The "$users" variable needs to be a comma separate list of email addresses. Such as "a@a.com, b@b.com, c@c.com". Here is the function I use to retrieve email addresses from my database and turn them into a coma separated list: function calendar_mail() { //Database connection $conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Error connecting to mysql'); mysql_select_db(DB_NAME); $sql = 'SELECT user_email FROM phpbb_users WHERE user_notify_calendar="1" AND user_email!=""'; $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $recepients = $recepients.$row['user_email'] . ", "; } $recepients = rtrim($recepients, " ,"); return $recepients; } The examples on the php website are also very helpful: http://us.php.net/function.mail Thank you too ! Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-714107 Share on other sites More sharing options...
samoi Posted December 12, 2008 Author Share Posted December 12, 2008 Do your users want you to basically give out their emal addresses to other users? Of course NO !! What kind of question is this?? Is there any problem using this script!? will it shows other users the email list of users!??? Quote Link to comment https://forums.phpfreaks.com/topic/136584-solved-help-teach-me-how-to-send-mail-through-email/#findComment-714109 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.