////////////////////////////////////////////////////////////
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",//Subject
"How is 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 for
PHP ' s mail () function; Heck, it's PHP ' s mail function done right:-)
You could override this method to:
(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);
}
}
}
?>
http://www.bkjia.com/PHPjc/315941.html www.bkjia.com true http://www.bkjia.com/PHPjc/315941.html techarticle ? PHP//////////////////////////////////////////////////////////////emailclass 0.5//class for sending mail//// Paul Schreiber//php@paulschreiber.com//http://paulschreiber.com//...