Jump to content

How to throttle mailinglist script?


hashstar

Recommended Posts

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());
}




?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...

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....

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.