Afficher un message
Vieux 26/03/2008, 11h27   #2
petersprc
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to send message auto matically

Hi,

Here is the script:

--- begin mailer.php ---
<?php

error_reporting(E_ALL | E_STRICT);

require_once('MDB2.php');
require_once('MDB2/Date.php');

class Mailer
{
var $db;

function getDb()
{
if (empty($this->db)) {
$dsn = 'mysql://u:p@h/d';
$this->db = MDB2::singleton($dsn);
$this->db->setOption('portability', MDB2_PORTABILITY_FIX_CASE);
$this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$this->db->loadModule('Extended');
}
return $this->db;
}

function process()
{
PEAR::setErrorHandling(PEAR_ERROR_DIE);
if (isset($_GET['action']) && $_GET['action'] == 'send') {
$this->send();
}
}

function send()
{
echo "<p>\n";
$this->log("Starting mailer.");
$begin = mktime(0, 0, 0, date('n'), date('j') - 1, date('Y'));
$end = mktime(23, 59, 59, date('n'), date('j') - 1, date('Y'));
$this->log("Date range: " . date('Y-m-d H:i:s', $begin) . ' - ' .
date('Y-m-d H:i:s', $end) . '.');

$db = $this->getDb();
$sql = 'select name, email, date from subscriber where ' .
'date >= :begin and date <= :end';
$query = $db->prepare($sql);
$params = array('begin' => MDB2_Date::unix2Mdbstamp($begin),
'end' => MDB2_Date::unix2Mdbstamp($end));
$rs = $query->execute($params);

while ($subscriber = $rs->fetchRow()) {
$this->sendTo($subscriber);
}

$this->log("Finished mailer.");
echo "</p>\n";
}

function sendTo($subscriber)
{
$this->log("Seding e-mail to {$subscriber['name']} at " .
$subscriber['email'] . ".");
$msg = "Dear {$subscriber['name']},\n\n";
$msg .= "This is your automated notice.\n";
mail($subscriber['email'], 'Notice', $msg, 'From:
info@example.test');
}

function log($msg)
{
echo date('[Y-m-d H:i:s]');
echo ' [mailer] ';
echo $msg;
echo "<br>\n";
}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Mailer</title>
</head>
<body>
<h1>Mailer</h1>

<?php

$mailer = new Mailer;
$mailer->process();

?>

<p>Click below to send e-mails.</p>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>">
<input type=hidden name=action value="send">
<input type=submit value=Send>
</form>
</body>
</html>
--- end mailer.php ---

Run this script daily but putting something like this line in your
crontab:

30 8 * * * /usr/bin/lynx -source 'http://example.test/admin/mailer.php?
action=send' 2>&1

Regards,

John Peters

On Mar 26, 12:30 am, anbu <anbuphpcod...@gmail.com> wrote:
> there in one database and one table that have three field one is
> name and another one is date
> and last is email address
>
> data are stored in following ways
>
> name date email address
>
> anbu 2008-03-26 someth...@gmail.com
>
> automatically tomrrow (2008-03-27) send message to that email
> address(someth...@gmail.com)
>
> give solution
>
> thank you


  Réponse avec citation
 
Page generated in 0,07800 seconds with 9 queries