How can optimise this email class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

How can optimise this email class

Post by fastfingertips »

I'm interested to send only text and html emails (withouth attachments) and i would like to know if there is any method to optimise this:

Code: Select all

<?php

class emails {
  
  var $email_destination;
  var $email_sender;
  var $email_subject;
  var $email_body;
  var $email_headers;
  var $email_error;
  
  function processEmail($to,$from,$subject,$message,$type) {
    $this->email_destination=$to; //<-- in my script here i'm checking the email structure to be ok
    $this->email_sender=$from; //<-- in my script here i'm checking the email structure to be ok
    $this->email_subject=$subject;
    $this->email_body=$message;
    $this->email_error='';
    
    $this->headers='MIME-Version: 1.0\r\n';
    if(strcasecmp($type,'html')==0) {
      $this->headers .='Content-Type: text/html; charset="iso-8859-1"\r\n';
    }
    else {
      $this->headers .='Content-Type: text/plain; charset="iso-8859-1"\r\n';
    }
    $headers .= "To: ".$this->email_destination." <".$this->email_destination.">\r\n";
    $headers .= "From: ".$this->email_sender." <".$this->email_sender.">\r\n";
    $this->sendEmail()
  }
   
  function sendEmail() {
    $sent=mail($this->email_destination, $this->email_subject, $this->email_body, $headers);
    if(!$sent) {
      $this->email_error=$this->email_destination;
    }
  }    
}

?>
Any clue?
Post Reply