rn14 Posted February 21, 2007 Share Posted February 21, 2007 My problem is that I have email addresss stored in a mysql database table. I need to loop through these values so that each address is sent as an individual email. Any suggestions please?? Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 <?php $sql="SELECT `email` FROM `MyTable`"; if ($query=mysql_query($sql)) { while ($req=mysql_fetch_array($query)) { mail($req['email'], subject, message); } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 You could either just send one mail with lots of BCC, or send many mails. PHP is not really meant to send many mails with mail(), you might need to look at a mailer program. Quote Link to comment Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 That code seems to work magic!(Thanks) would it be possible to individualise each of these emails with names stored in another column in the database? Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Share Posted February 21, 2007 $query="SELECT `email` FROM `MyTable`"; $result= mysql_query($query); $num=mysql_num_rows($result); if ($result) { while ($array= mysql_fetch_assoc($result)) { /////////////////////////////////////////////////// send email using mailform /////////////////////////////////// //send email from contact us page ///// // Your email address $admin_email = $array[email]; $email = "EventReminder"; $subject = "Subject for email"; // The email body for site owner $message = " message body..."; mail($admin_email, $subject, $message, "From: $email"); Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Share Posted February 21, 2007 This will send an email to everyone on that email column Quote Link to comment Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 I need to modify the first piece of code so that each email can be personalised with a name coming from another column in this table?? Quote Link to comment Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 or i could modify either of those suggestions(doesnt matter which) so it can do this? Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Share Posted February 21, 2007 Not sure what you are asking but the code that I gave you works. It will send an email to the recipient just like you sent them their own email. They will not see other address, they will only see their own. Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 To do what you ask, simply run that script and put the name in the message. Ex: mail(EMAIL Address, Subject, "Dear, {$req['Name']}"); Quote Link to comment Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 I get an unexpected string error when I run this last bit? Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 You need to replace those words with the appropriate variable... Via: mail($MyEmailVariable, $MySubject, $MyMessage); Ex: $sql="SELECT `email` FROM `MyTable`"; if ($query=mysql_query($sql)) { while ($req=mysql_fetch_array($query)) { mail($req['email'], "This is My Subject Line", "Dear {$req['User']}"); } } Quote Link to comment Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 I got this working thanks very much for your help Quote Link to comment 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.