1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: require_once("AWLUtilities.php");
12: 13: 14: 15:
16: class EMail
17: {
18: 19: 20:
21:
22: 23: 24: 25:
26: private $To;
27:
28: 29: 30: 31:
32: private $From;
33:
34: 35: 36: 37:
38: private $Cc;
39:
40: 41: 42: 43:
44: private $Bcc;
45:
46: 47: 48: 49:
50: private $ErrorsTo;
51:
52: 53: 54: 55:
56: private $ReplyTo;
57:
58: 59: 60: 61:
62: private $Sender;
63:
64: 65: 66: 67:
68: private $Subject;
69:
70: 71: 72: 73:
74: private $Body;
75:
76:
77: 78: 79: 80: 81:
82: function __construct( $subject = "", $to = "" ) {
83:
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:
95: 96: 97: 98: 99: 100:
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:
108: 109: 110: 111: 112:
113: function AddTo( $recipient ) {
114: return $this->_AppendDelimited($this->To, $recipient);
115: }
116:
117: 118: 119: 120:
121: function To() {
122: return $this->To;
123: }
124:
125: 126: 127: 128: 129:
130: function AddCc( $recipient ) {
131: return $this->_AppendDelimited($this->Cc, $recipient);
132: }
133:
134: 135: 136: 137: 138:
139: function AddBcc( $recipient ) {
140: return $this->_AppendDelimited($this->Bcc, $recipient);
141: }
142:
143: 144: 145: 146: 147:
148: function AddReplyTo( $recipient ) {
149: return $this->_AppendDelimited($this->ReplyTo, $recipient);
150: }
151:
152: 153: 154: 155: 156:
157: function AddErrorsTo( $recipient ) {
158: return $this->_AppendDelimited($this->ErrorsTo, $recipient);
159: }
160:
161:
162: 163: 164: 165: 166:
167: function SetFrom( $sender ) {
168: $this->From = $sender;
169: return $sender;
170: }
171:
172:
173: 174: 175: 176: 177:
178: function SetSender( $sender ) {
179: $this->Sender = $sender;
180: return $sender;
181: }
182:
183:
184: 185: 186: 187: 188:
189: function SetSubject( $subject ) {
190: $this->Subject = $subject;
191: return $subject;
192: }
193:
194:
195: 196: 197: 198: 199:
200: function SetBody( $body ) {
201: $this->Body = $body;
202: return $body;
203: }
204:
205:
206: 207: 208: 209:
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:
223: 224: 225: 226:
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:
241: 242: 243: 244: 245:
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: }
260: