premora Posted May 20, 2011 Share Posted May 20, 2011 Hi there everyone. I'm really confused about this as I want to email eveyone in my DB when a new Event is created by a member. I have a test code which I used to make sure it works and it sends to 5 email addresses (which is all of them) in the test table. This works fine. All members with a 0 get the mail. So I now just took the code and changed the table name (obviously!!) and put it in my live site which has 50 members so far. It now doesn't send any emails??? Not sure why this is as the code is exactly the same (except the table name). $result = mysql_query("SELECT email FROM membership WHERE send_as_email = '0'"); while ($row = mysql_fetch_array($result)) { sendMail($row[0]); } mysql_free_result($result); function sendMail($to){ $subject = 'New Event Created; $message = "Hi there,\n Just letting you know of a new Event that has been created.\n Title: $title\n Town: $town\n Date: $date_convert\n For more details or to attend this Event, please login \n Many thanks\n The Team\n \n ****************************************************************************\n THIS EMAIL IS AUTOMATED. DO NOT REPLY.\n To turn notifications off, change the notification settings in your Profile.\n ****************************************************************************\n"; $headers = 'From: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } Link to comment https://forums.phpfreaks.com/topic/236948-email-all-users-in-mysql-database/ Share on other sites More sharing options...
Albos Posted May 20, 2011 Share Posted May 20, 2011 Hi, It sounds like your server does not want to send the email and probably has nothing to do with the database/php code. I would first make sure to see if you are allowed to use SMTP on your web server, if you are make sure that there is nothing blocking the emails being sent. I know some servers will limit to say 10 emails within a set amount of time so you are not using your server to send mass spam emails. Worth checking both. Hope this Helps Regards Albos Link to comment https://forums.phpfreaks.com/topic/236948-email-all-users-in-mysql-database/#findComment-1217975 Share on other sites More sharing options...
premora Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks. I had another search around and found this website which has now fixed my issue. http://www.kidslovepc.com/php-tutorial/php-mail-bulk.shtml Link to comment https://forums.phpfreaks.com/topic/236948-email-all-users-in-mysql-database/#findComment-1217988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.