Location: PHPKode > scripts > EasyPhpMassEmail > easyphpmassemail/mass_email_example_queue.php
<?php

/**

EasyPhpMassEmail Example version 0.0.1 - PHP5

Copyright (c) 2011 JF Nutbroek <hide@address.com>
Visit http://www.mywebmymail.com for more information 

Permission to use, copy, modify, and/or distribute this software for any
purpose without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/

// The EasyPHPMassEmail classs requires sessions to work
session_start();

// Include the class
include_once('easyphpmassemail.class.php');
$massemail = new easyphpmassemail;

// Check if we have a mass email session running
if ($massemail -> Progress() != 'Inactive') {

	// We have a session running, send the next batch of emails by calling Sendemails(); when it returns false we are finished
	if (!$massemail -> Sendemails()) {
	
		// Our static page, all emails have been send
		echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . "\n";
		echo '<HTML><HEAD><TITLE>Mass Email queue</TITLE></HEAD><BODY>' . "\n";
		echo 'Mass Email 100% completed!<br />' . "\n";
		// Check if we have failed emails and list them
		// Note: this does not check if emails arrived, only if the mail command was successfully executed
		$failed_emails = $massemail -> Failed();
		if (count($failed_emails) > 0) {
			echo '<p>Failed email(s):</p>' . "\n";
			foreach ($failed_emails as $failed) {
				echo $failed . '<br />' . "\n";
			}
		}
		echo '</BODY></HTML>' . "\n";
		// Cleanup this session
		$massemail -> Cleanup();
		
	} else {
	
		// Our dynamic page - which reloads to send a new batch of emails
		echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . "\n";
		echo '<HTML><HEAD><TITLE>Mass Email queue</TITLE></HEAD><BODY onload="javascript: setTimeout(\'location.reload(true);\',3000);">' . "\n";
		// Display our progress 
		echo 'Email session in progress ' . $massemail -> Progress('%') . ' completed .. please wait';
		echo '</BODY></HTML>' . "\n";
		
	}
	
} else {

	// Our static empty page, no email session active or completed
	echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . "\n";
	echo '<HTML><HEAD><TITLE>Mass Email queue</TITLE></HEAD><BODY>' . "\n";
	echo '</BODY></HTML>' . "\n";
	
}

?>
Return current item: EasyPhpMassEmail