Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Gianluca Zanferrari  >  Mail dispatcher  >  example.php  >  Download  
File: example.php
Role: Auxiliary script
Content type: text/plain
Description: Gui interface
Class: Mail dispatcher
Send mail to many recipients in batches
Author: By
Last change:
Date: 2010-09-03 06:43
Size: 5,502 bytes
 

Contents

Class file image Download
<? session_start();
require (
'maildispatcher.class.php');

/*
initiate the class
*/
$maildispatcher = new maildispatcher;

/*
set the trigger on TRUE for sending e-mails
otherwise for testing, it DOESN'T
*/

// $maildispatcher->set_trigger(TRUE); // uncomment here for sending e-mails. // TEST/OPERATIONAL modus //

/*
set some recipients for sending your message.
if test_email submitted send only 1 test e-mail.
*/
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['test_email']) && '' != trim($_POST['test_email']))
{
    
    
$maildispatcher->set_emails(array(trim($_POST['test_email'])));
    
$testDispatcher 1;
    
}
elseif(
$_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['test_email']) && '' == trim($_POST['test_email']))
{
    
    
$maildispatcher->set_emails(explode("\r\n",trim($_POST['recipients'])));
    
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mail Dispatcher</title>
<style>
body {font-family:Arial, Gadget, sans-serif; font-size:12px; margin:5px 100px 100px 100px}
.error_div {background-color:#000; color: #0F0;font-size:14px;padding:5px;}
h2 {font-size:24px; text-transform:uppercase; margin:5px 0 5px 3px;}
</style>
<script language="javascript" type="text/javascript">
function perhour(){
    
    var delay = document.getElementById('delay').value;
    var jump = document.getElementById('jump').value;
    
    var perhour = 60*60/delay*jump;
    var per15 = perhour/4;
    var permin = perhour/60;
    
    document.getElementById('ph').innerHTML = '&nbsp;&nbsp;E-mails sent per hour: ' + parseInt(perhour) + '<br />&nbsp;&nbsp;E-mails sent per 15 min.: ' + parseInt(per15) +  '<br />&nbsp;&nbsp;E-mails sent per min.: ' + parseInt(permin);
    
}
</script>
</head>
<body>
<div style="background-color:#900; color:#FFF;">
<h2>Mail dispatcher</h2>
<div id="d2" style="padding:5px; font-size:125%; width:450px; float:left;">COUNTER</div>
<? 
/*
* Display the MODUS (TEST:OPERATIONAL)
*/
$maildispatcher->is_triggered();

/*
* validation (display's feedback)
*/
$err $maildispatcher->validate($_POST);
if(
FALSE !== $err && isset($_POST['top'])) echo('<div style="clear:both" class="error_div">'.$err.'</div>');
?>
<span id="ph"></span>
<div style="clear:both; height:0px;"></div>
</div>
<div style="padding:5px; background-color:#900; color:#FFF;"><textarea name="sent" id="sent" cols="45" rows="7" style="width:450px" onfocus="blur();">Do not write in here...</textarea><br /><input type="button" name="recall" id="recall" value="Recall the form" style="visibility:hidden" onclick="document.location='<?=$_SERVER['PHP_SELF']?>'" /></div>
<div style="padding:5px; background-color: #339; color:#FFF; font-size:125%;">
<?

/*
Send e-mails with parameters:
1- Subject of email message
2- Message to be sent
3- incremental counter for slicing e-mail array (DO NOT CHANGE IT, THE POST FORM TAKES CARE OF THAT)
4- additional headers
*/
if($_SERVER['REQUEST_METHOD'] == 'POST' && FALSE === $err):
    
$headers "FROM: My company<mycompany@domainxy.com>\r\n";
    
$headers .= "Reply-To: My company<mycompany@domainxy.com>\r\n";
    
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
$maildispatcher->send($_POST['subject'], $_POST['message'], $_POST['top'], $headers);    
endif;

(
$_SERVER['REQUEST_METHOD'] == 'POST' && FALSE !== $err || $_SERVER['REQUEST_METHOD'] != 'POST') ? $st '' $st 'visibility:hidden';
?>
<form id="form1" name="form1" method="post" action="?" style=" <?=$st?>">
  Subject:<br />
  <input name="subject" type="text" id="subject" value="<?=$_SESSION['subject']?>" style="width:450px" />
  <br />
  Message:
  <br />
<textarea name="message" id="message" cols="45" rows="7" style="width:450px"><?=$_SESSION['message'];?></textarea>
* The message to send (HTML allowed)<br />
  <input name="top" type="hidden" id="top" value="<?php echo (isset($_SESSION['top']) && isset($_SESSION['jump'])) ? ($_SESSION['top']+$_SESSION['jump']) : 0;?>" />
Jump:<br />
  <input name="jump" type="text" id="jump" style="width:450px" value="<?php echo (isset($_SESSION['jump'])) ? $_SESSION['jump'] : 3;?>" onchange="perhour()" /> * Number of e-mails sent per block.
  <br />
Delay:<br />
  <input name="delay" type="text" id="delay" style="width:450px" value="<?php echo (isset($_SESSION['delay'])) ? $_SESSION['delay'] : 5;?>" onchange="perhour()" /> 
  * Number of seconds standing-by between two e-mail sending blocks.
  <br />
Recipients:<br />
<textarea name="recipients" id="recipients" cols="45" rows="12" style="width:450px">myemail@webweb.com
someother@someone.com
anotherone@myemail.com
idontknowmore@gmail.com
wearespamming@spammachine.com
pleasedontspam@me.com
ihatespam@spammer.com
bahbah@mail.com
almostdone@mailaddr.com
thelastone@thelast.com</textarea> 
* List of recipients where e-mail is sent to.
<br />
Testing e-mail address:
<br />
  <input name="test_email" type="text" id="test_email" style="width:450px" value="<?php if(isset($_POST['test_email'])) echo(stripslashes($_POST['test_email']));?>" /> * If setted send only 1 e-mail as test instead of the whole bulk.
  <br />
  <input type="button" name="dispatcherSend" id="dispatcherSend" value="Submit" onclick="document.forms['form1'].submit()" />
</form>
</div>
</body>
</html>