Back to index

awl  0.53
EMail.php
Go to the documentation of this file.
00001 <?php
00011 require_once("AWLUtilities.php");
00016 class EMail
00017 {
00026   private $To;         // To:
00027 
00032   private $From;       // etc...
00033 
00038   private $Cc;
00039 
00044   private $Bcc;
00045 
00050   private $ErrorsTo;
00051 
00056   private $ReplyTo;
00057 
00062   private $Sender;
00063 
00068   private $Subject;
00069 
00074   private $Body;
00082   function __construct( $subject = "", $to = "" ) {
00083     // Initialise with some defaults
00084     $this->From    = "";
00085     $this->Subject = $subject;
00086     $this->To      = $to;
00087     $this->Cc      = "";
00088     $this->Bcc     = "";
00089     $this->ErrorsTo = "";
00090     $this->ReplyTo = "";
00091     $this->Sender  = "";
00092     $this->Body    = "";
00093   }
00094 
00101   private function _AppendDelimited( &$onto, $extra ) {
00102     if ( !isset($extra) || $extra == "" ) return false;
00103     if ( $onto != "" ) $onto .= ", ";
00104     $onto .= $extra;
00105     return $onto;
00106   }
00107 
00113   function AddTo( $recipient ) {
00114     return $this->_AppendDelimited($this->To, $recipient);
00115   }
00116 
00122   function AddCc( $recipient ) {
00123     return $this->_AppendDelimited($this->Cc, $recipient);
00124   }
00125 
00131   function AddBcc( $recipient ) {
00132     return $this->_AppendDelimited($this->Bcc, $recipient);
00133   }
00134 
00140   function AddReplyTo( $recipient ) {
00141     return $this->_AppendDelimited($this->ReplyTo, $recipient);
00142   }
00143 
00149   function AddErrorsTo( $recipient ) {
00150     return $this->_AppendDelimited($this->ErrorsTo, $recipient);
00151   }
00152 
00153 
00159   function SetFrom( $sender ) {
00160     $this->From = $sender;
00161     return $sender;
00162   }
00163 
00164 
00170   function SetSender( $sender ) {
00171     $this->Sender = $sender;
00172     return $sender;
00173   }
00174 
00175 
00181   function SetSubject( $subject ) {
00182     $this->Subject = $subject;
00183     return $subject;
00184   }
00185 
00186 
00192   function SetBody( $body ) {
00193     $this->Body = $body;
00194     return $body;
00195   }
00196 
00197 
00202   function Send( $additional_headers = "" ) {
00203     if ( !empty($this->From) )     $additional_headers .= "From: $this->From\r\n";
00204     if ( !empty($this->Cc) )       $additional_headers .= "Cc: $this->Cc\r\n";
00205     if ( !empty($this->Bcc) )      $additional_headers .= "Bcc: $this->Bcc\r\n";
00206     if ( !empty($this->ReplyTo) )  $additional_headers .= "Reply-To: $this->ReplyTo\r\n";
00207     if ( !empty($this->ErrorsTo) ) $additional_headers .= "Errors-To: $this->ErrorsTo\r\n";
00208 
00209     $additional_parameters = "";
00210     if ( !empty($this->Sender) ) $additional_parameters = "-f$this->Sender";
00211     mail( $this->To, $this->Subject, $this->Body, $additional_headers, $additional_parameters );
00212   }
00213 
00214 
00219   function PretendLog( $additional_headers = "" ) {
00220     if ( !empty($this->From) )     dbg_error_log('LOG', "From: $this->From");
00221     if ( !empty($this->Cc) )       dbg_error_log('LOG', "Cc: $this->Cc");
00222     if ( !empty($this->Bcc) )      dbg_error_log('LOG', "Bcc: $this->Bcc");
00223     if ( !empty($this->ReplyTo) )  dbg_error_log('LOG', "Reply-To: $this->ReplyTo");
00224     if ( !empty($this->ErrorsTo) ) dbg_error_log('LOG', "Errors-To: $this->ErrorsTo");
00225 
00226     $additional_parameters = "";
00227     if ( !empty($this->Sender) ) dbg_error_log('LOG', "Envelope Sender set to: $this->Sender");
00228     dbg_error_log('LOG', "To: $this->To");
00229     dbg_error_log('LOG', "Subject: $this->Subject");
00230     dbg_error_log('LOG', "Body: $this->Body");
00231   }
00232 
00238   function Pretend( $additional_headers = "" ) {
00239     if ( !empty($this->From) )     print("From: $this->From\r\n");
00240     if ( !empty($this->Cc) )       print("Cc: $this->Cc\r\n");
00241     if ( !empty($this->Bcc) )      print("Bcc: $this->Bcc\r\n");
00242     if ( !empty($this->ReplyTo) )  print("Reply-To: $this->ReplyTo\r\n");
00243     if ( !empty($this->ErrorsTo) ) print("Errors-To: $this->ErrorsTo\r\n");
00244 
00245     $additional_parameters = "";
00246     if ( !empty($this->Sender) ) print("Envelope Sender set to: $this->Sender\r\n");
00247     print("To: $this->To\r\n");
00248     print("Subject: $this->Subject\r\n");
00249     print("Body: $this->Body\r\n");
00250   }
00251 }