Mail PHP
Views:
some old functions to help deal with email. One for sending and one for getting the unread message count of someones mailbox over imap
There is also a Mail Class in PHP
<?php
function send_mail($fromname, $fromaddress, $toname, $toaddress, $subject, $message)
{
// Copyright 2005 ECRIA LLC, http://www.ECRIA.com
// Please use or modify for any purpose but leave this notice unchanged.
// Modified by Kieran Whitbread, original can be found on www.php.net
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";
return mail('"'.$toname.'" <'.$toaddress.'>', $subject, $message, $headers);
}
function unread_emails($username, $password, $connectionUrl="{mail.varndean.ac.uk/novalidate-cert/norsh}")
/* Copyriht Kieran Whitbread 2005 */
{
imap_timeout(1, 1);
$mbox = imap_open($connectionUrl, $username, $password, OP_HALFOPEN);
if ($mbox)
{
$count = 0;
$folders = imap_listmailbox($mbox, $connectionUrl, "*");
foreach ($folders as $val)
{
$status = imap_status($mbox, $val, SA_UNSEEN);
if ($status)
{
$count = $count + $status->unseen;
}
else
{
return imap_last_error();
}
}
imap_close($mbox);
return $count;
}
else
{
return "error";
}
}
?>
