<? 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 D bcclist can be strings or arrays of strings
// (those strings shocould be valid email addresses
// example
// -------
// $ M = new email ("Hello there ", // subject
// "how are you? ", // Message body
//" PAUL ", // sender's name
/" foo@foobar.com ", // sender's email
// array ("paul@foobar.com", "foo@bar.com"), // to: recipients
/"paul@whereever.com" // CC: recipient
//);
// print "mail sent, result was ". $ M-> send ();
//
If (! Defined ('mail _ class_defined ')){
Define ('mail _ class_defined ', 1 );
Class email {
// The constructor!
Function email ($ subject, $ message, $ sendername, $ senderemail, $ tolist, $ cclist = 0, $ bcclist = 0, $ replyto = 0 ){
$ This-> sender = $ sendername. "<$ senderemail> ";
$ This-> replyto = $ replyto;
$ This-> subject = $ subject;
$ This-> message = $ message;
// Set the to: recipient (s)
If (is_array ($ tolist )){
$ This-> to = join ($ tolist ,",");
} Else {
$ This-> to = $ tolist;
}
// Set the CC: recipient (s)
If (is_array ($ cclist) & sizeof ($ cclist )){
$ This-> cc = join ($ cclist ,",");
} Elseif ($ cclist ){
$ This-> cc = $ cclist;
}
// Set the BCC: recipient (s)
If (is_array ($ bcclist) & sizeof ($ bcclist )){
$ This-> BCC = join ($ bcclist ,",");
} Elseif ($ bcclist ){
$ This-> BCC = $ bcclist;
}
}
// Send the message; this is actually just a wrapper
// PHP's mail () function; heck, it's PHP's mail function done right
// You cocould override this method:
// (A) use sendmail directly
// (B) Do SMTP with sockets
Function send (){
// Create the headers needed by PHP's mail () function
// Sender
$ This-> headers = "from:". $ this-> sender. "\ n ";
// Reply-to address
If ($ this-> replyto ){
$ This-> headers. = "reply-to:". $ this-> replyto. "\ n ";
}
// CC: recipient (s)
If ($ this-> CC ){
$ This-> headers. = "cc:". $ this-> cc. "\ n ";
}
// BCC: recipient (s)
If ($ this-> BCC ){
$ This-> headers. = "BCC:". $ this-> BCC. "\ n ";
}
Return mail ($ this-> to, $ this-> subject, $ this-> message, $ this-> headers );
}
}
}
?>