Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SMTPMail {
- //Member Variables
- public $host, $username, $password, $from, $to, $subject, $html_body, $plaintext_body, $status, $attachment_name;
- private $smtp, $mail, $body, $headers;
- //Constructor
- public function __construct( $host, $username, $password, $from ) {
- //Import PEAR SMTP Library
- require_once("Mail.php");
- require_once("Mail/mime.php");
- //Set Member Variables from Parameters
- $this->host = $host;
- $this->username = $username;
- $this->password = $password;
- $this->from = $from;
- //Create SMTP Connection
- $this->smtp = Mail::factory('smtp',
- array ('host' => $this->host,
- 'auth' => true,
- 'username' => $this->username,
- 'password' => $this->password)
- );
- //Return True For Constructor Tests
- return true;
- }
- //Send Mail
- public function sendMail( $to, $subject, $html_body, $plaintext_body = "", $attachment_name="" ) {
- //Set Member Variables from Parameters
- $this->to = $to;
- $this->subject = $subject;
- $this->html_body = $html_body;
- $this->plaintext_body = $plaintext_body;
- $this->attachment = $attachment_name;
- var_dump($this->attachment);
- //Build Headers
- $headers = array('From' => $this->from,
- 'To' => $this->to,
- 'Subject' => $this->subject
- );
- //Set MIME Types and Build Message
- $mime = new Mail_mime();
- $mime->setTXTBody( $this->plaintext_body );
- $mime->setHTMLBody( $this->html_body );
- $mime->addAttachment( $this->attachment,'application/octet-stream' );
- $this->body = $mime->get();
- $this->headers = $mime->headers($headers);
- //Send the Message
- $this->mail = $this->smtp->send($this->to, $this->headers, $this->body);
- //Check for Error Message, Return True/False if E-mail Sent or Not
- if (PEAR::isError($mail)) {
- $this->status = "FAIL:Error Code: ".$mail->getMessage();
- return false;
- }
- else {
- $this->status = "OK:Sent";
- //$this->status = "OK:".$mail->getMessage();
- return true;
- }
- }
- //Accessor Methods
- public function getStatus() {
- //Return E-Mail Status Message
- return $this->status;
- }
- public function getMail() {
- //Return Mail Object Created by PEAR Mail/PEAR Mime
- return $this->mail();
- }
- public function getBody() {
- //Return Message Object Created by PEAR Mail/PEAR Mime
- return $this->body;
- }
- public function getHeaders() {
- //Return Message Headers Object Created by PEAR Mail/PEAR Mime
- return $this->headers;
- }
- public function showAttachment() {
- //Return Message Headers Object Created by PEAR Mail/PEAR Mime
- return $this->attachment;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement