Andrew's Web Libraries (AWL)
EMail.php
1 <?php
11 require_once("AWLUtilities.php");
16 class EMail
17 {
26  private $To; // To:
27 
32  private $From; // etc...
33 
38  private $Cc;
39 
44  private $Bcc;
45 
50  private $ErrorsTo;
51 
56  private $ReplyTo;
57 
62  private $Sender;
63 
68  private $Subject;
69 
74  private $Body;
82  function __construct( $subject = "", $to = "" ) {
83  // Initialise with some defaults
84  $this->From = "";
85  $this->Subject = $subject;
86  $this->To = $to;
87  $this->Cc = "";
88  $this->Bcc = "";
89  $this->ErrorsTo = "";
90  $this->ReplyTo = "";
91  $this->Sender = "";
92  $this->Body = "";
93  }
94 
101  private function _AppendDelimited( &$onto, $extra ) {
102  if ( !isset($extra) || $extra == "" ) return false;
103  if ( $onto != "" ) $onto .= ", ";
104  $onto .= $extra;
105  return $onto;
106  }
107 
113  function AddTo( $recipient ) {
114  return $this->_AppendDelimited($this->To, $recipient);
115  }
116 
121  function To() {
122  return $this->To;
123  }
124 
130  function AddCc( $recipient ) {
131  return $this->_AppendDelimited($this->Cc, $recipient);
132  }
133 
139  function AddBcc( $recipient ) {
140  return $this->_AppendDelimited($this->Bcc, $recipient);
141  }
142 
148  function AddReplyTo( $recipient ) {
149  return $this->_AppendDelimited($this->ReplyTo, $recipient);
150  }
151 
157  function AddErrorsTo( $recipient ) {
158  return $this->_AppendDelimited($this->ErrorsTo, $recipient);
159  }
160 
161 
167  function SetFrom( $sender ) {
168  $this->From = $sender;
169  return $sender;
170  }
171 
172 
178  function SetSender( $sender ) {
179  $this->Sender = $sender;
180  return $sender;
181  }
182 
183 
189  function SetSubject( $subject ) {
190  $this->Subject = $subject;
191  return $subject;
192  }
193 
194 
200  function SetBody( $body ) {
201  $this->Body = $body;
202  return $body;
203  }
204 
205 
210  function Send( $additional_headers = "" ) {
211  if ( !empty($this->From) ) $additional_headers .= "From: $this->From\r\n";
212  if ( !empty($this->Cc) ) $additional_headers .= "Cc: $this->Cc\r\n";
213  if ( !empty($this->Bcc) ) $additional_headers .= "Bcc: $this->Bcc\r\n";
214  if ( !empty($this->ReplyTo) ) $additional_headers .= "Reply-To: $this->ReplyTo\r\n";
215  if ( !empty($this->ErrorsTo) ) $additional_headers .= "Errors-To: $this->ErrorsTo\r\n";
216 
217  $additional_parameters = "";
218  if ( !empty($this->Sender) ) $additional_parameters = "-f$this->Sender";
219  mail( $this->To, $this->Subject, $this->Body, $additional_headers, $additional_parameters );
220  }
221 
222 
227  function PretendLog( $additional_headers = "" ) {
228  if ( !empty($this->From) ) dbg_error_log('LOG', "From: $this->From");
229  if ( !empty($this->Cc) ) dbg_error_log('LOG', "Cc: $this->Cc");
230  if ( !empty($this->Bcc) ) dbg_error_log('LOG', "Bcc: $this->Bcc");
231  if ( !empty($this->ReplyTo) ) dbg_error_log('LOG', "Reply-To: $this->ReplyTo");
232  if ( !empty($this->ErrorsTo) ) dbg_error_log('LOG', "Errors-To: $this->ErrorsTo");
233 
234  $additional_parameters = "";
235  if ( !empty($this->Sender) ) dbg_error_log('LOG', "Envelope Sender set to: $this->Sender");
236  dbg_error_log('LOG', "To: $this->To");
237  dbg_error_log('LOG', "Subject: $this->Subject");
238  dbg_error_log('LOG', "Body: $this->Body");
239  }
240 
246  function Pretend( $additional_headers = "" ) {
247  if ( !empty($this->From) ) print("From: $this->From\r\n");
248  if ( !empty($this->Cc) ) print("Cc: $this->Cc\r\n");
249  if ( !empty($this->Bcc) ) print("Bcc: $this->Bcc\r\n");
250  if ( !empty($this->ReplyTo) ) print("Reply-To: $this->ReplyTo\r\n");
251  if ( !empty($this->ErrorsTo) ) print("Errors-To: $this->ErrorsTo\r\n");
252 
253  $additional_parameters = "";
254  if ( !empty($this->Sender) ) print("Envelope Sender set to: $this->Sender\r\n");
255  print("To: $this->To\r\n");
256  print("Subject: $this->Subject\r\n");
257  print("Body: $this->Body\r\n");
258  }
259 }
Definition: EMail.php:17
Pretend( $additional_headers="")
Definition: EMail.php:246
SetBody( $body)
Definition: EMail.php:200
SetFrom( $sender)
Definition: EMail.php:167
AddErrorsTo( $recipient)
Definition: EMail.php:157
AddCc( $recipient)
Definition: EMail.php:130
To()
Definition: EMail.php:121
AddReplyTo( $recipient)
Definition: EMail.php:148
AddBcc( $recipient)
Definition: EMail.php:139
__construct( $subject="", $to="")
Definition: EMail.php:82
SetSubject( $subject)
Definition: EMail.php:189
SetSender( $sender)
Definition: EMail.php:178
AddTo( $recipient)
Definition: EMail.php:113
Send( $additional_headers="")
Definition: EMail.php:210
_AppendDelimited(&$onto, $extra)
Definition: EMail.php:101
PretendLog( $additional_headers="")
Definition: EMail.php:227