Hi, do I need to LIMIT my blast script to fire out an emailer or can I just take it out. We have around 500 email address in our database. Having to reload the script is going to become painful - is there anything I can do?

My hosting provider does not support cronjobs.

<?php
include_once "connection.php";
$sql = mysql_query("SELECT * FROM addresses WHERE received='1' LIMIT 20");
$numRows = mysql_num_rows($sql); 
// Added for "End Campaign Check" at the bottom of this file(not shown on the video)
$mail_body = '';
while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$email = $row["email"];
	
	$mail_body = 'Hello this is a test!';
    $subject = "TEST EMAILER";
    $headers  = "From:info@mifsuds.com\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "$email";

    $mail_result = mail($to, $subject, $mail_body, $headers);
	
	if ($mail_result) {
		mysql_query("UPDATE addresses SET received='0' WHERE email='$email' LIMIT 1");
	} else {
// this else statement can be used to write into an error log if the mail function fails
// It can also be removed if you do not need error logging
	}
	
}
?>
<?php
// This section is script I discussed adding to this file on video
// This section is for sending the site owner a message informing them that
// all people in the database have been sent the newsletter for the current campaign
if (!$numRows == 0) { // $numRows is set on line 4 using the existing query
	 
	 $subj = "Newsletter Campaign Has Ended";
	 $body = "The current newsletter campaign has ended. All have been sent the newsletter.";
     $hdr  = "From:info@test.com\r\n";
     $hdr .= "Content-type: text/html\r\n";
     mail("example@gmail.com", $subj, $body, $hdr);
	
}
// End Check Section
?>

Recommended Answers

All 5 Replies

If you are running an email blast, I don't think that 500 emails should be an issue but it all depends on your web host. I have sent several thousand email blasts without a problem. If necessary, you could put a governor on it and only issue them at a certain pace (a short sleep between emails). That probably isn't necessary.

If you don't have Cron and you don't want to do it manually, there are other alternatives. PHPJobScheduler is one of them. This depends on having a site that receives fairly regular traffic that can trigger your program. A second alternative is to trigger it from your desktop. You could use Autoit to do that.

Hi, thanks for your reply. Yes, I'm not sure whether I should limit amount sent and stagger it hourly or something. I have around 600 to send out. The mailers images are downloaded from the website so there is no attachments, etc.

What is the issue with sending a large amount of messages at once? Do hosting companies frown upon it?

It could tie up their mail server so yes they might not be happy but 600 isn't all that many. I'd look at the hosting provider's policies. If you can't see anything there about it, I would give it a shot with all 600.

Just keep in mind that if you annoy your hosting company, it could come back and bite you in a big way.

Most ISPs host mail for many clients on a server. Event the suggestion of spamming can get an IP blacklisted, and if that happens it takes out mail for every domain on that server. For that reason both my hosting company and my registrar/DNS provider have policies that say all your domains are toast if spamming is suspected on even one.

Harsh, but understandable.

Your host's support department can tell you what the hourly limit is.

To be on the safe side, consider chunking your list into batches just below that limit, i.e. 490 for a limit of 500, and sending a chunk every 70 minutes to be sure you can never go over that number in a hour.

Hi there, thanks so much for your post, very useful. I've got in touch with our webhost and they say we're able to send an unlimited amount of emails. So...

When I send the next emailer, should I send it via the web (instead of using MAMP on my machine). Currently, we don't have a MySQL database with our host but I do have a personal one, would it be ok the execute the script from our host via the browser and for it to connect to my personal database or will this cause me issues on my personal one due to the large amount of email addresses (7,500)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.