This class can be used for mass email. The testing environment is Linux. The system needs to install sendmail to use it.
if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {
define('MAIL_CLASS_DEFINED' , 1 );
class email {
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;
// Define recipients
if ( is_array($toList) ) {
$this->to = join( $toList, "," );
} else {
$this->to = $toList;
}
// Define CC list
if ( is_array($ccList) && sizeof($ccList) ) {
$this->cc = join( $ccList, "," );
} elseif ( $ccList ) {
$this->cc = $ccList;
}
// Define password carbon copy list
if ( is_array($bccList) && sizeof($bccList) ) {
$this->bcc = join( $bccList, "," );
} elseif ( $ bccList ) {
$this->bcc = $bccList;
}
}
// Send function
// Use the mail() function in php to send email
function send () {
//Sender
$this->headers = "From: " . $this->sender . " ";
// Reply address
if ( $ this->replyTo ) {
$this->headers .= "Reply-To: " . $this->replyTo . " ";
}
// CC
if ( $this->cc ) {
$this->headers .= "Cc: " . $this->cc . " ";
}
// Secret Cc
if ( $this->bcc ) {
$this->headers .= "Bcc: " . $this->bcc . " ";
}
return mail ( $this-> ;to, $this->subject, $this->message, $this->headers ); //return result
}
}
}
?>
Description:
Parameter Description
----------
- The following parameters are required: subject, message, senderName, senderEmail and toList
- These parameters are are optional: ccList, bccList and replyTo
- toList, ccList and bccList must be valid email addresses