hashstar Posted June 5, 2012 Share Posted June 5, 2012 Hi there, I have a mailing list script that i am using to send out an email to everyone on my database. The problem i am having is that my host will only let me send the email to 4 addresses at once and there is a limit of 500 per hour. How can i make it so the script just sends out 4 emails at a time an no more than 500 an hour? this is the code i am using: <?php require('connect.php'); // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/include/MailClass.inc'); /* Note: set_time_limit() does not work with safe_mode enabled */ $result_message = ''; if (isset($_POST['submit'])) { $errors = array(); if (empty($_POST['email_addresses'])) { $errors['emails'] = 'No emails selected.'; } // here you can/should loop through and verify email addresses to avoid spamming; put a restriction to # of emails allowed to be sent, etc. // santizing/controlling your email functions is greatly overlooked and can cause your site to be dropped by your hosting provider if your site is being used to send gobs of spam if (empty($errors)) { $result_message = 'There was a problem sending this mail!'; // instantiate the class $mailer = new FreakMailer(); // Build foreach ($_POST['email_addresses'] as $email_address) { $mailer->AddBCC($email_address); } // Set the subject $mailer->Subject = 'New Products from The Organic Grow Shop'; $mailer->isHTML(true); if ($mailer->Send()) { $result_message = 'Mail sent!'; } $mailer->ClearAddresses(); $mailer->ClearAttachments(); } } $sql = "SELECT * FROM mailinglist"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { echo (!empty($result_message) ? $result_message .'<br/><br/>' : ''); echo " <h1>Mailing List</h1> Send to<br/><br/> <form action='send.php' method='POST'> "; while ($getrow = mysql_fetch_assoc($result)) { echo "<input type='checkbox' name='email_addresses[]' value='". $getrow['email'] ."' unchecked='unchecked'/>". $getrow['email'] ."<br>"; } echo "<input type='submit' name='submit' value='Send »'/></form>"; } else { echo 'Add some email addresses.'; } } else { trigger_error(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/263722-how-to-throttle-mailinglist-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2012 Share Posted June 5, 2012 You would typically use a database table as a queue to hold a list of email address that you want to send to and have a cron job/scheduled task periodically run and select the correct number of entries from the queue and send the emails. Quote Link to comment https://forums.phpfreaks.com/topic/263722-how-to-throttle-mailinglist-script/#findComment-1351502 Share on other sites More sharing options...
hashstar Posted June 8, 2012 Author Share Posted June 8, 2012 This cron stuff seems complicated. Is there a simple easy way of doing this with just php? Thanks, Hash Quote Link to comment https://forums.phpfreaks.com/topic/263722-how-to-throttle-mailinglist-script/#findComment-1352091 Share on other sites More sharing options...
hashstar Posted September 29, 2012 Author Share Posted September 29, 2012 Hello people, Can anyone out there help me figure out how to get my php mailing list to send an email to everyone in my database? I am using php mailer and have tried using the 'MAILQUEUE_THROTTLE' function. but it does not seem to work ! Is there any other way around this, i just can't understand why it won't work!! when i try to send emails from my database manually i can only send 4 at a time.... Quote Link to comment https://forums.phpfreaks.com/topic/263722-how-to-throttle-mailinglist-script/#findComment-1381721 Share on other sites More sharing options...
drewdan Posted September 29, 2012 Share Posted September 29, 2012 You could assign a unix timestamp to all of the entries in the database, and then get your cron job to run every minute to see if any emails need to be sent, or you could use ajax and the setinterval function in javascript to run the sendmail script you have every 30 seconds, but you would have to update your database to know when someone has been sent an email or not and limit the sending to 4 emails. The other choice is, get a dedicated server you can find some pretty cheap servers these days! Quote Link to comment https://forums.phpfreaks.com/topic/263722-how-to-throttle-mailinglist-script/#findComment-1381804 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.