<?php
class mailer
{
var $headers; // An array of headers
var $recipients; // An array of recipients
var $subject; // The message subject
var $message; // The message body
function from($name, $email)
{ // Sets who the email was from
@ini_set('sendmail_from','newsletters@tececo.com');
$this->headers[] = 'From: '.$email.' <'.$name.'>';
}
function add_recipient($email)
{ // Adds a recipient in the to: field
$this->recipients[] = $email;
}
function add_cc($email)
{ //Adds a carbon copy address
$this->headers[] = 'CC: '.$email;
}
function add_bcc($email)
{ //Adds a blind carbon copy address
$this->headers[] = 'BCC: '.$email;
}
function subject($subject)
{ //Sets the message subject
$this->subject = $subject;
}
function message($message)
{ //Sets the message body
$this->message = $message;
}
function custom_header($headername, $headervalue)
{ //Adds a custom header
$this->headers[] = $headername.': '.$headervalue;
}
function send()
{ //sends the email
$recipients_separated = implode(",", $this->recipients);
$headers = "";
foreach($this->headers as $header)
{
$header .= $headers."\r\n";
}
mail($recipients_separated, $this->subject, $this->message, $headers);
}
};
Usage Example:
$mailout = new mailer;
$mailout->from('sender@example.com', 'Sender');
$mailout->add_recipient('person1@example.com');//add a recipient in the to: field
$mailout->add_cc('person2@example.com');//carbon copy
$mailout->add_bcc('person3@example.com');//blind carbon copy
$mailout->subject('Test');//set subject
$mailout->message('Hi,
FILLER
---------------------------------------------
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
---------------------------------------------
Thank You!
');//set message body
$mailout->send();//send email(s)
?>