Class for sending emails to multiple addresses

Source: Internet
Author: User
Class for sending emails to multiple addresses, reading class for sending emails to multiple addresses ,? Php /////////////////////////////////////// /////////////////// EmailClass0.5 // classforsendingmail //// PaulSchreiber & nb... "> <LINK
//////////////////////////////////////// ////////////////////
// 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 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 );
}
}


}
?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.