<?php
////////////////////////////////////////////////////////////
// EmailClass 0.5
// class for sending mail
//
// Paul Schreiber
// php@paulschreiber.com
// http://paulschreiber.com/
//
// parameters
// ----------
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional
// - toList, ccList and bccList can be strings or arrays of strings
// (those strings should be valid email addresses
//
// example
// -------
// $m = new email ( "hello there",/t // subject
///t/t "how are you?",/t // message body
///t/t "paul",/t/t // sender's name
///t/t "foo@foobar.com",/t // sender's email
///t/t array("paul@foobar.com", "foo@bar.com"), // To: recipients
///t/t "paul@whereever.com" // Cc: recipient
///t/t );
//
// print "mail sent, result was" . $m->send();
//
//
//
if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {
/tdefine('MAIL_CLASS_DEFINED', 1 );
class email {
/t// the constructor!
/tfunction email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {
/t/t$this->sender = $senderName . " <$senderEmail>";
/t/t$this->replyTo = $replyTo;
/t/t$this->subject = $subject;
/t/t$this->message = $message;
/t/t// set the To: recipient(s)
/t/tif ( is_array($toList) ) {
/t/t/t$this->to = join( $toList, "," );
/t/t} else {
/t/t/t$this->to = $toList;
/t/t}
/t/t// set the Cc: recipient(s)
/t/tif ( is_array($ccList) && sizeof($ccList) ) {
/t/t/t$this->cc = join( $ccList, "," );
/t/t} elseif ( $ccList ) {
/t/t/t$this->cc = $ccList;
/t/t}
/t/t
/t/t// set the Bcc: recipient(s)
/t/tif ( is_array($bccList) && sizeof($bccList) ) {
/t/t/t$this->bcc = join( $bccList, "," );
/t/t} elseif ( $bccList ) {
/t/t/t$this->bcc = $bccList;
/t/t}
/t}
/t// send the message; this is actually just a wrapper for
/t// PHP's mail() function; heck, it's PHP's mail function done right :-)
/t// you could override this method to:
/t// (a) use sendmail directly
/t// (b) do SMTP with sockets
/tfunction send () {
/t/t// create the headers needed by PHP's mail() function
/t/t// sender
/t/t$this->headers = "From: " . $this->sender . "/n";
/t/t// reply-to address
/t/tif ( $this->replyTo ) {
/t/t/t$this->headers .= "Reply-To: " . $this->replyTo . "/n";
/t/t}
/t/t// Cc: recipient(s)
/t/tif ( $this->cc ) {
/t/t/t$this->headers .= "Cc: " . $this->cc . "/n";
/t/t}
/t/t// Bcc: recipient(s)
/t/tif ( $this->bcc ) {
/t/t/t$this->headers .= "Bcc: " . $this->bcc . "/n";
/t/t}
/t
/t/treturn mail ( $this->to, $this->subject, $this->message, $this->headers );
/t}
}
}
?>