· 7 years ago · Oct 02, 2018, 04:00 AM
1<?php
2error_reporting(0);
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}
14if(isset($_POST['action'] ) ){
15
16$b = query_str($_POST);
17parse_str($b);
18$sslclick=lrtrim($sslclick);
19$action=lrtrim($action);
20$message=lrtrim($message);
21$emaillist=lrtrim($emaillist);
22$from=lrtrim($from);
23$reconnect=lrtrim($reconnect);
24$epriority=lrtrim($epriority);
25$my_smtp=lrtrim($my_smtp);
26$ssl_port=lrtrim($ssl_port);
27$smtp_username=lrtrim($smtp_username);
28$smtp_password=lrtrim($smtp_password);
29$replyto=lrtrim($replyto);
30$subject_base=lrtrim($subject);
31$realname_base=lrtrim($realname);
32$file_name=$_FILES['file']['name'];
33$file=$_FILES['file']['tmp_name'];
34$urlz=lrtrim($urlz);
35$contenttype=lrtrim($contenttype);
36$encode_text=$_POST['encode'];
37
38
39 $message = urlencode($message);
40 $message = ereg_replace("%5C%22", "%22", $message);
41 $message = urldecode($message);
42 $message = stripslashes($message);
43 $subject = stripslashes($subject);
44 if ($encode_text == "yes") {
45 $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
46 $subject = str_replace(' ', '_', $subject);
47 $subject = "=?UTF-8?Q?$subject?=";
48 $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
49 $realname = str_replace(' ', '_', $realname);
50 $realname = "=?UTF-8?Q?$realname?=";
51 }
52}
53?>
54
55<html>
56
57<head>
58
59<title>PoLLaRda</title>
60
61<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
62
63<style type="text/css">
64<!--
65.style1 {
66 font-family: Geneva, Arial, Helvetica, sans-serif;
67 font-size: 12px;
68}
69-->
70</style>
71<style type="text/css">
72<!--
73.style1 {
74 font-size: 10px;
75 font-family: Geneva, Arial, Helvetica, sans-serif;
76}
77-->
78</style>
79</head>
80<body bgcolor="#FFFFFF" text="#000000">
81<p align="center"><font size="5" face="Bauhaus 93">Mailer Inbox Sender</font></p>
82<form name="form1" method="post" action="" enctype="multipart/form-data">
83
84 <br>
85
86 <table width="100%" border="0" height="407">
87
88 <tr>
89
90 <td width="100%" colspan="4" bgcolor="#666666" height="36">
91
92 <b>
93
94 <font face="Arial" size="2" color="#FFFFFF"> SMTP SETUP</font></b></td>
95
96 </tr>
97 <tr>
98
99 <td width="10%" height="22" bgcolor="#E8E8E8">
100
101 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Login:</font></div>
102
103 </td>
104
105 <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
106
107 <input type="text" name="smtp_username" value="<?php echo $smtp_username; ?>" size="30">
108
109 </font></td>
110
111 <td width="31%" height="22" bgcolor="#E8E8E8">
112
113 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Pass:</font></div>
114
115 </td>
116
117 <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
118
119 <input type="password" name="smtp_password" value="<? echo $smtp_password;?>" size="30">
120
121 </font></td>
122
123 </tr>
124 <tr>
125
126 <td width="10%" height="22" bgcolor="#E8E8E8">
127
128 <div align="right">
129 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
130
131 </td>
132
133 <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
134
135 <input type="text" name="ssl_port" value="<?php echo $ssl_port;?>" size="5">
136 (optional)</font></td>
137
138 <td width="31%" height="22" bgcolor="#E8E8E8">
139
140 <div align="right">
141 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP Server
142 Smtp:</font></div>
143
144 </td>
145
146 <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
147
148 <input type="text" name="my_smtp" value="<?php echo $my_smtp;?>" size="30">
149
150 </font></td>
151
152 </tr>
153 <tr>
154
155 <td width="10%" height="22" bgcolor="#E8E8E8">
156
157 <p align="right">
158 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
159
160 <td width="18%" height="22" bgcolor="#E8E8E8">
161 <input type="checkbox" name="sslclick" value="ON" <?php if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
162
163 <td width="31%" height="22" bgcolor="#E8E8E8">
164
165 <p align="right">
166 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
167 After:</font></td>
168
169 <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
170
171 <input type="text" name="reconnect" value="<?php echo $reconnect;?>" size="5">
172 EMAILS</font></td>
173
174 </tr>
175 <tr>
176
177 <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4">
178
179 <p align="center">
180 <font face="Arial" style="font-size: 9pt" color="#800000"><b>"</b> If
181 you dont have SMTP login, leave blank queries above <b>"</b></font></td>
182
183 </tr>
184
185 <tr>
186
187 <td width="10%" height="19">
188
189 </td>
190
191 <td width="18%" height="19"> </td>
192
193 <td width="31%" height="19">
194
195 </td>
196
197 <td width="41%" height="19"> </td>
198
199 </tr>
200
201 <tr>
202
203 <td width="100%" colspan="4" bgcolor="#666666" height="36">
204
205 <b>
206
207 <font face="Arial" size="2" color="#FFFFFF"> MESSAGE SETUP</font></b></td>
208
209 </tr>
210 <tr>
211
212 <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
213 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Attach File :</font></div>
214 </td>
215
216 <td width="59%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8" colSpan="3">
217 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
218
219<input type="file" name="file" size="124">
220
221 </font></td>
222
223 </tr>
224 <tr>
225
226 <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
227
228 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
229
230 Email:</font></div>
231
232 </td>
233
234 <td width="18%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
235
236 <input type="text" name="from" value="<?php echo $from;?>" size="30">
237
238 </font></td>
239
240 <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
241
242 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
243
244 Name:</font></div>
245
246 </td>
247
248 <td width="41%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
249
250 <input type="text" name="realname" value="<?php echo $realname_base;?>" size="30">
251
252 </font></td>
253
254 </tr>
255 <tr>
256
257 <td width="10%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
258
259 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
260
261 </td>
262
263 <td width="18%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
264
265 <input type="text" name="replyto" value="<?=$replyto;?>" size="30">
266
267 </font></td>
268
269 <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
270
271 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
272 Email Priority:</font></td>
273
274 <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
275
276 </font><select name="epriority" id="listMethod" onchange="showHideListConfig()">
277 <option value="" <?php if(strlen($epriority)< 1){print "selected";} ?> >- Please Choose -</option>
278 <option value="1" <?php if($epriority == "1"){print "selected";} ?> >High</option>
279 <option value="3" <?php if($epriority == "3"){print "selected";} ?> >Normal</option>
280 <option value="5" <?php if($epriority == "5"){print "selected";} ?> >Low</option>
281 </select></td>
282
283 </tr>
284
285 <tr>
286
287 <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
288
289 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
290
291 </td>
292
293 <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
294
295 <input type="text" name="subject" value="<?php echo $subject_base;?>" size="90">
296
297 </font></td>
298
299 </tr>
300
301 <tr>
302
303 <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
304
305 </td>
306
307 <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
308
309 <font color="#FF0000">Encode sending information ?</font> <select size="1" name="encode">
310 <option <?php if($encode_text == "yes"){print "selected";} ?>>yes</option>
311 <option <?php if($encode_text == "no"){print "selected";} ?>>no</option>
312 </select></font></td>
313
314 </tr>
315
316 <tr valign="top">
317
318<td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
319
320 <textarea name="message" cols="60" rows="10"><?php echo $message;?></textarea>
321
322 <br>
323
324 <input type="radio" name="contenttype" value="plain" >
325
326 Plain
327
328 <input type="radio" name="contenttype" value="html" checked>
329
330 HTML
331
332 <input type="hidden" name="action" value="send">
333
334 <input type="submit" value="Send Message">
335
336 </font></td>
337
338 <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
339
340 <textarea name="emaillist" cols="30" rows="10"><?php echo $emaillist;?></textarea>
341
342 </font></td>
343
344 </tr>
345
346 </table>
347
348</form>
349
350
351
352<?php
353
354if ($action){
355 if (!$from && !$subject && !$message && !$emaillist){
356 print "<script>alert('Please complete all fields before sending your message.'); </script>";
357 die(); }
358
359class SMTP
360{
361 /**
362 * SMTP server port
363 * @var int
364 */
365 var $SMTP_PORT = 25;
366
367 /**
368 * SMTP reply line ending
369 * @var string
370 */
371 var $CRLF = "\r\n";
372
373 /**
374 * Sets whether debugging is turned on
375 * @var bool
376 */
377 var $do_debug; # the level of debug to perform
378
379 /**
380 * Sets VERP use on/off (default is off)
381 * @var bool
382 */
383 var $do_verp = false;
384
385 /**#@+
386 * @access private
387 */
388 var $smtp_conn; # the socket to the server
389 var $error; # error if any on the last call
390 var $helo_rply; # the reply the server sent to us for HELO
391 /**#@-*/
392
393 /**
394 * Initialize the class so that the data is in a known state.
395 * @access public
396 * @return void
397 */
398 function SMTP() {
399 $this->smtp_conn = 0;
400 $this->error = null;
401 $this->helo_rply = null;
402
403 $this->do_debug = 0;
404 }
405
406 /*************************************************************
407 * CONNECTION FUNCTIONS *
408 ***********************************************************/
409
410 /**
411 * Connect to the server specified on the port specified.
412 * If the port is not specified use the default SMTP_PORT.
413 * If tval is specified then a connection will try and be
414 * established with the server for that number of seconds.
415 * If tval is not specified the default is 30 seconds to
416 * try on the connection.
417 *
418 * SMTP CODE SUCCESS: 220
419 * SMTP CODE FAILURE: 421
420 * @access public
421 * @return bool
422 */
423 function Connect($host,$port=0,$tval=30) {
424 # set the error val to null so there is no confusion
425 $this->error = null;
426
427 # make sure we are __not__ connected
428 if($this->connected()) {
429 # ok we are connected! what should we do?
430 # for now we will just give an error saying we
431 # are already connected
432 $this->error = array("error" => "Already connected to a server");
433 return false;
434 }
435
436 if(empty($port)) {
437 $port = $this->SMTP_PORT;
438 }
439
440 #connect to the smtp server
441 $this->smtp_conn = fsockopen($host, # the host of the server
442 $port, # the port to use
443 $errno, # error number if any
444 $errstr, # error message if any
445 $tval); # give up after ? secs
446 # verify we connected properly
447 if(empty($this->smtp_conn)) {
448 $this->error = array("error" => "Failed to connect to server",
449 "errno" => $errno,
450 "errstr" => $errstr);
451 if($this->do_debug >= 1) {
452 echo "SMTP -> ERROR: " . $this->error["error"] .
453 ": $errstr ($errno)" . $this->CRLF;
454 }
455 return false;
456 }
457
458 # sometimes the SMTP server takes a little longer to respond
459 # so we will give it a longer timeout for the first read
460 // Windows still does not have support for this timeout function
461 if(substr(PHP_OS, 0, 3) != "WIN")
462 socket_set_timeout($this->smtp_conn, $tval, 0);
463
464 # get any announcement stuff
465 $announce = $this->get_lines();
466
467 # set the timeout of any socket functions at 1/10 of a second
468 //if(function_exists("socket_set_timeout"))
469 // socket_set_timeout($this->smtp_conn, 0, 100000);
470
471 if($this->do_debug >= 2) {
472 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
473 }
474
475 return true;
476 }
477
478 /**
479 * Performs SMTP authentication. Must be run after running the
480 * Hello() method. Returns true if successfully authenticated.
481 * @access public
482 * @return bool
483 */
484 function Authenticate($username, $password) {
485 // Start authentication
486 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
487
488 $rply = $this->get_lines();
489 $code = substr($rply,0,3);
490
491 if($code != 334) {
492 $this->error =
493 array("error" => "AUTH not accepted from server",
494 "smtp_code" => $code,
495 "smtp_msg" => substr($rply,4));
496 if($this->do_debug >= 1) {
497 echo "SMTP -> ERROR: " . $this->error["error"] .
498 ": " . $rply . $this->CRLF;
499 }
500 return false;
501 }
502
503 // Send encoded username
504 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
505
506 $rply = $this->get_lines();
507 $code = substr($rply,0,3);
508
509 if($code != 334) {
510 $this->error =
511 array("error" => "Username not accepted from server",
512 "smtp_code" => $code,
513 "smtp_msg" => substr($rply,4));
514 if($this->do_debug >= 1) {
515 echo "SMTP -> ERROR: " . $this->error["error"] .
516 ": " . $rply . $this->CRLF;
517 }
518 return false;
519 }
520
521 // Send encoded password
522 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
523
524 $rply = $this->get_lines();
525 $code = substr($rply,0,3);
526
527 if($code != 235) {
528 $this->error =
529 array("error" => "Password not accepted from server",
530 "smtp_code" => $code,
531 "smtp_msg" => substr($rply,4));
532 if($this->do_debug >= 1) {
533 echo "SMTP -> ERROR: " . $this->error["error"] .
534 ": " . $rply . $this->CRLF;
535 }
536 return false;
537 }
538
539 return true;
540 }
541
542 /**
543 * Returns true if connected to a server otherwise false
544 * @access private
545 * @return bool
546 */
547 function Connected() {
548 if(!empty($this->smtp_conn)) {
549 $sock_status = socket_get_status($this->smtp_conn);
550 if($sock_status["eof"]) {
551 # hmm this is an odd situation... the socket is
552 # valid but we are not connected anymore
553 if($this->do_debug >= 1) {
554 echo "SMTP -> NOTICE:" . $this->CRLF .
555 "EOF caught while checking if connected";
556 }
557 $this->Close();
558 return false;
559 }
560 return true; # everything looks good
561 }
562 return false;
563 }
564
565 /**
566 * Closes the socket and cleans up the state of the class.
567 * It is not considered good to use this function without
568 * first trying to use QUIT.
569 * @access public
570 * @return void
571 */
572 function Close() {
573 $this->error = null; # so there is no confusion
574 $this->helo_rply = null;
575 if(!empty($this->smtp_conn)) {
576 # close the connection and cleanup
577 fclose($this->smtp_conn);
578 $this->smtp_conn = 0;
579 }
580 }
581
582 /***************************************************************
583 * SMTP COMMANDS *
584 *************************************************************/
585
586 /**
587 * Issues a data command and sends the msg_data to the server
588 * finializing the mail transaction. $msg_data is the message
589 * that is to be send with the headers. Each header needs to be
590 * on a single line followed by a <CRLF> with the message headers
591 * and the message body being seperated by and additional <CRLF>.
592 *
593 * Implements rfc 821: DATA <CRLF>
594 *
595 * SMTP CODE INTERMEDIATE: 354
596 * [data]
597 * <CRLF>.<CRLF>
598 * SMTP CODE SUCCESS: 250
599 * SMTP CODE FAILURE: 552,554,451,452
600 * SMTP CODE FAILURE: 451,554
601 * SMTP CODE ERROR : 500,501,503,421
602 * @access public
603 * @return bool
604 */
605 function Data($msg_data) {
606 $this->error = null; # so no confusion is caused
607
608 if(!$this->connected()) {
609 $this->error = array(
610 "error" => "Called Data() without being connected");
611 return false;
612 }
613
614 fputs($this->smtp_conn,"DATA" . $this->CRLF);
615
616 $rply = $this->get_lines();
617 $code = substr($rply,0,3);
618
619 if($this->do_debug >= 2) {
620 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
621 }
622
623 if($code != 354) {
624 $this->error =
625 array("error" => "DATA command not accepted from server",
626 "smtp_code" => $code,
627 "smtp_msg" => substr($rply,4));
628 if($this->do_debug >= 1) {
629 echo "SMTP -> ERROR: " . $this->error["error"] .
630 ": " . $rply . $this->CRLF;
631 }
632 return false;
633 }
634
635 # the server is ready to accept data!
636 # according to rfc 821 we should not send more than 1000
637 # including the CRLF
638 # characters on a single line so we will break the data up
639 # into lines by \r and/or \n then if needed we will break
640 # each of those into smaller lines to fit within the limit.
641 # in addition we will be looking for lines that start with
642 # a period '.' and append and additional period '.' to that
643 # line. NOTE: this does not count towards are limit.
644
645 # normalize the line breaks so we know the explode works
646 $msg_data = str_replace("\r\n","\n",$msg_data);
647 $msg_data = str_replace("\r","\n",$msg_data);
648 $lines = explode("\n",$msg_data);
649
650 # we need to find a good way to determine is headers are
651 # in the msg_data or if it is a straight msg body
652 # currently I am assuming rfc 822 definitions of msg headers
653 # and if the first field of the first line (':' sperated)
654 # does not contain a space then it _should_ be a header
655 # and we can process all lines before a blank "" line as
656 # headers.
657 $field = substr($lines[0],0,strpos($lines[0],":"));
658 $in_headers = false;
659 if(!empty($field) && !strstr($field," ")) {
660 $in_headers = true;
661 }
662
663 $max_line_length = 998; # used below; set here for ease in change
664
665 while(list(,$line) = @each($lines)) {
666 $lines_out = null;
667 if($line == "" && $in_headers) {
668 $in_headers = false;
669 }
670 # ok we need to break this line up into several
671 # smaller lines
672 while(strlen($line) > $max_line_length) {
673 $pos = strrpos(substr($line,0,$max_line_length)," ");
674
675 # Patch to fix DOS attack
676 if(!$pos) {
677 $pos = $max_line_length - 1;
678 }
679
680 $lines_out[] = substr($line,0,$pos);
681 $line = substr($line,$pos + 1);
682 # if we are processing headers we need to
683 # add a LWSP-char to the front of the new line
684 # rfc 822 on long msg headers
685 if($in_headers) {
686 $line = "\t" . $line;
687 }
688 }
689 $lines_out[] = $line;
690
691 # now send the lines to the server
692 while(list(,$line_out) = @each($lines_out)) {
693 if(strlen($line_out) > 0)
694 {
695 if(substr($line_out, 0, 1) == ".") {
696 $line_out = "." . $line_out;
697 }
698 }
699 fputs($this->smtp_conn,$line_out . $this->CRLF);
700 }
701 }
702
703 # ok all the message data has been sent so lets get this
704 # over with aleady
705 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
706
707 $rply = $this->get_lines();
708 $code = substr($rply,0,3);
709
710 if($this->do_debug >= 2) {
711 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
712 }
713
714 if($code != 250) {
715 $this->error =
716 array("error" => "DATA not accepted from server",
717 "smtp_code" => $code,
718 "smtp_msg" => substr($rply,4));
719 if($this->do_debug >= 1) {
720 echo "SMTP -> ERROR: " . $this->error["error"] .
721 ": " . $rply . $this->CRLF;
722 }
723 return false;
724 }
725 return true;
726 }
727
728 /**
729 * Expand takes the name and asks the server to list all the
730 * people who are members of the _list_. Expand will return
731 * back and array of the result or false if an error occurs.
732 * Each value in the array returned has the format of:
733 * [ <full-name> <sp> ] <path>
734 * The definition of <path> is defined in rfc 821
735 *
736 * Implements rfc 821: EXPN <SP> <string> <CRLF>
737 *
738 * SMTP CODE SUCCESS: 250
739 * SMTP CODE FAILURE: 550
740 * SMTP CODE ERROR : 500,501,502,504,421
741 * @access public
742 * @return string array
743 */
744 function Expand($name) {
745 $this->error = null; # so no confusion is caused
746
747 if(!$this->connected()) {
748 $this->error = array(
749 "error" => "Called Expand() without being connected");
750 return false;
751 }
752
753 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
754
755 $rply = $this->get_lines();
756 $code = substr($rply,0,3);
757
758 if($this->do_debug >= 2) {
759 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
760 }
761
762 if($code != 250) {
763 $this->error =
764 array("error" => "EXPN not accepted from server",
765 "smtp_code" => $code,
766 "smtp_msg" => substr($rply,4));
767 if($this->do_debug >= 1) {
768 echo "SMTP -> ERROR: " . $this->error["error"] .
769 ": " . $rply . $this->CRLF;
770 }
771 return false;
772 }
773
774 # parse the reply and place in our array to return to user
775 $entries = explode($this->CRLF,$rply);
776 while(list(,$l) = @each($entries)) {
777 $list[] = substr($l,4);
778 }
779
780 return $list;
781 }
782
783 /**
784 * Sends the HELO command to the smtp server.
785 * This makes sure that we and the server are in
786 * the same known state.
787 *
788 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
789 *
790 * SMTP CODE SUCCESS: 250
791 * SMTP CODE ERROR : 500, 501, 504, 421
792 * @access public
793 * @return bool
794 */
795 function Hello($host="") {
796 $this->error = null; # so no confusion is caused
797
798 if(!$this->connected()) {
799 $this->error = array(
800 "error" => "Called Hello() without being connected");
801 return false;
802 }
803
804 # if a hostname for the HELO was not specified determine
805 # a suitable one to send
806 if(empty($host)) {
807 # we need to determine some sort of appopiate default
808 # to send to the server
809 $host = "localhost";
810 }
811
812 // Send extended hello first (RFC 2821)
813 if(!$this->SendHello("EHLO", $host))
814 {
815 if(!$this->SendHello("HELO", $host))
816 return false;
817 }
818
819 return true;
820 }
821
822 /**
823 * Sends a HELO/EHLO command.
824 * @access private
825 * @return bool
826 */
827 function SendHello($hello, $host) {
828 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
829
830 $rply = $this->get_lines();
831 $code = substr($rply,0,3);
832
833 if($this->do_debug >= 2) {
834 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
835 }
836
837 if($code != 250) {
838 $this->error =
839 array("error" => $hello . " not accepted from server",
840 "smtp_code" => $code,
841 "smtp_msg" => substr($rply,4));
842 if($this->do_debug >= 1) {
843 echo "SMTP -> ERROR: " . $this->error["error"] .
844 ": " . $rply . $this->CRLF;
845 }
846 return false;
847 }
848
849 $this->helo_rply = $rply;
850
851 return true;
852 }
853
854 /**
855 * Gets help information on the keyword specified. If the keyword
856 * is not specified then returns generic help, ussually contianing
857 * A list of keywords that help is available on. This function
858 * returns the results back to the user. It is up to the user to
859 * handle the returned data. If an error occurs then false is
860 * returned with $this->error set appropiately.
861 *
862 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
863 *
864 * SMTP CODE SUCCESS: 211,214
865 * SMTP CODE ERROR : 500,501,502,504,421
866 * @access public
867 * @return string
868 */
869 function Help($keyword="") {
870 $this->error = null; # to avoid confusion
871
872 if(!$this->connected()) {
873 $this->error = array(
874 "error" => "Called Help() without being connected");
875 return false;
876 }
877
878 $extra = "";
879 if(!empty($keyword)) {
880 $extra = " " . $keyword;
881 }
882
883 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
884
885 $rply = $this->get_lines();
886 $code = substr($rply,0,3);
887
888 if($this->do_debug >= 2) {
889 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
890 }
891
892 if($code != 211 && $code != 214) {
893 $this->error =
894 array("error" => "HELP not accepted from server",
895 "smtp_code" => $code,
896 "smtp_msg" => substr($rply,4));
897 if($this->do_debug >= 1) {
898 echo "SMTP -> ERROR: " . $this->error["error"] .
899 ": " . $rply . $this->CRLF;
900 }
901 return false;
902 }
903
904 return $rply;
905 }
906
907 /**
908 * Starts a mail transaction from the email address specified in
909 * $from. Returns true if successful or false otherwise. If True
910 * the mail transaction is started and then one or more Recipient
911 * commands may be called followed by a Data command.
912 *
913 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
914 *
915 * SMTP CODE SUCCESS: 250
916 * SMTP CODE SUCCESS: 552,451,452
917 * SMTP CODE SUCCESS: 500,501,421
918 * @access public
919 * @return bool
920 */
921 function Mail($from) {
922 $this->error = null; # so no confusion is caused
923
924 if(!$this->connected()) {
925 $this->error = array(
926 "error" => "Called Mail() without being connected");
927 return false;
928 }
929
930 $useVerp = ($this->do_verp ? "XVERP" : "");
931 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
932
933 $rply = $this->get_lines();
934 $code = substr($rply,0,3);
935
936 if($this->do_debug >= 2) {
937 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
938 }
939
940 if($code != 250) {
941 $this->error =
942 array("error" => "MAIL not accepted from server",
943 "smtp_code" => $code,
944 "smtp_msg" => substr($rply,4));
945 if($this->do_debug >= 1) {
946 echo "SMTP -> ERROR: " . $this->error["error"] .
947 ": " . $rply . $this->CRLF;
948 }
949 return false;
950 }
951 return true;
952 }
953
954 /**
955 * Sends the command NOOP to the SMTP server.
956 *
957 * Implements from rfc 821: NOOP <CRLF>
958 *
959 * SMTP CODE SUCCESS: 250
960 * SMTP CODE ERROR : 500, 421
961 * @access public
962 * @return bool
963 */
964 function Noop() {
965 $this->error = null; # so no confusion is caused
966
967 if(!$this->connected()) {
968 $this->error = array(
969 "error" => "Called Noop() without being connected");
970 return false;
971 }
972
973 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
974
975 $rply = $this->get_lines();
976 $code = substr($rply,0,3);
977
978 if($this->do_debug >= 2) {
979 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
980 }
981
982 if($code != 250) {
983 $this->error =
984 array("error" => "NOOP not accepted from server",
985 "smtp_code" => $code,
986 "smtp_msg" => substr($rply,4));
987 if($this->do_debug >= 1) {
988 echo "SMTP -> ERROR: " . $this->error["error"] .
989 ": " . $rply . $this->CRLF;
990 }
991 return false;
992 }
993 return true;
994 }
995
996 /**
997 * Sends the quit command to the server and then closes the socket
998 * if there is no error or the $close_on_error argument is true.
999 *
1000 * Implements from rfc 821: QUIT <CRLF>
1001 *
1002 * SMTP CODE SUCCESS: 221
1003 * SMTP CODE ERROR : 500
1004 * @access public
1005 * @return bool
1006 */
1007 function Quit($close_on_error=true) {
1008 $this->error = null; # so there is no confusion
1009
1010 if(!$this->connected()) {
1011 $this->error = array(
1012 "error" => "Called Quit() without being connected");
1013 return false;
1014 }
1015
1016 # send the quit command to the server
1017 fputs($this->smtp_conn,"quit" . $this->CRLF);
1018
1019 # get any good-bye messages
1020 $byemsg = $this->get_lines();
1021
1022 if($this->do_debug >= 2) {
1023 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
1024 }
1025
1026 $rval = true;
1027 $e = null;
1028
1029 $code = substr($byemsg,0,3);
1030 if($code != 221) {
1031 # use e as a tmp var cause Close will overwrite $this->error
1032 $e = array("error" => "SMTP server rejected quit command",
1033 "smtp_code" => $code,
1034 "smtp_rply" => substr($byemsg,4));
1035 $rval = false;
1036 if($this->do_debug >= 1) {
1037 echo "SMTP -> ERROR: " . $e["error"] . ": " .
1038 $byemsg . $this->CRLF;
1039 }
1040 }
1041
1042 if(empty($e) || $close_on_error) {
1043 $this->Close();
1044 }
1045
1046 return $rval;
1047 }
1048
1049 /**
1050 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
1051 * Returns true if the recipient was accepted false if it was rejected.
1052 *
1053 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
1054 *
1055 * SMTP CODE SUCCESS: 250,251
1056 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
1057 * SMTP CODE ERROR : 500,501,503,421
1058 * @access public
1059 * @return bool
1060 */
1061 function Recipient($to) {
1062 $this->error = null; # so no confusion is caused
1063
1064 if(!$this->connected()) {
1065 $this->error = array(
1066 "error" => "Called Recipient() without being connected");
1067 return false;
1068 }
1069
1070 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
1071
1072 $rply = $this->get_lines();
1073 $code = substr($rply,0,3);
1074
1075 if($this->do_debug >= 2) {
1076 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1077 }
1078
1079 if($code != 250 && $code != 251) {
1080 $this->error =
1081 array("error" => "RCPT not accepted from server",
1082 "smtp_code" => $code,
1083 "smtp_msg" => substr($rply,4));
1084 if($this->do_debug >= 1) {
1085 echo "SMTP -> ERROR: " . $this->error["error"] .
1086 ": " . $rply . $this->CRLF;
1087 }
1088 return false;
1089 }
1090 return true;
1091 }
1092
1093 /**
1094 * Sends the RSET command to abort and transaction that is
1095 * currently in progress. Returns true if successful false
1096 * otherwise.
1097 *
1098 * Implements rfc 821: RSET <CRLF>
1099 *
1100 * SMTP CODE SUCCESS: 250
1101 * SMTP CODE ERROR : 500,501,504,421
1102 * @access public
1103 * @return bool
1104 */
1105 function Reset() {
1106 $this->error = null; # so no confusion is caused
1107
1108 if(!$this->connected()) {
1109 $this->error = array(
1110 "error" => "Called Reset() without being connected");
1111 return false;
1112 }
1113
1114 fputs($this->smtp_conn,"RSET" . $this->CRLF);
1115
1116 $rply = $this->get_lines();
1117 $code = substr($rply,0,3);
1118
1119 if($this->do_debug >= 2) {
1120 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1121 }
1122
1123 if($code != 250) {
1124 $this->error =
1125 array("error" => "RSET failed",
1126 "smtp_code" => $code,
1127 "smtp_msg" => substr($rply,4));
1128 if($this->do_debug >= 1) {
1129 echo "SMTP -> ERROR: " . $this->error["error"] .
1130 ": " . $rply . $this->CRLF;
1131 }
1132 return false;
1133 }
1134
1135 return true;
1136 }
1137
1138 /**
1139 * Starts a mail transaction from the email address specified in
1140 * $from. Returns true if successful or false otherwise. If True
1141 * the mail transaction is started and then one or more Recipient
1142 * commands may be called followed by a Data command. This command
1143 * will send the message to the users terminal if they are logged
1144 * in.
1145 *
1146 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
1147 *
1148 * SMTP CODE SUCCESS: 250
1149 * SMTP CODE SUCCESS: 552,451,452
1150 * SMTP CODE SUCCESS: 500,501,502,421
1151 * @access public
1152 * @return bool
1153 */
1154 function Send($from) {
1155 $this->error = null; # so no confusion is caused
1156
1157 if(!$this->connected()) {
1158 $this->error = array(
1159 "error" => "Called Send() without being connected");
1160 return false;
1161 }
1162
1163 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
1164
1165 $rply = $this->get_lines();
1166 $code = substr($rply,0,3);
1167
1168 if($this->do_debug >= 2) {
1169 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1170 }
1171
1172 if($code != 250) {
1173 $this->error =
1174 array("error" => "SEND not accepted from server",
1175 "smtp_code" => $code,
1176 "smtp_msg" => substr($rply,4));
1177 if($this->do_debug >= 1) {
1178 echo "SMTP -> ERROR: " . $this->error["error"] .
1179 ": " . $rply . $this->CRLF;
1180 }
1181 return false;
1182 }
1183 return true;
1184 }
1185
1186 /**
1187 * Starts a mail transaction from the email address specified in
1188 * $from. Returns true if successful or false otherwise. If True
1189 * the mail transaction is started and then one or more Recipient
1190 * commands may be called followed by a Data command. This command
1191 * will send the message to the users terminal if they are logged
1192 * in and send them an email.
1193 *
1194 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
1195 *
1196 * SMTP CODE SUCCESS: 250
1197 * SMTP CODE SUCCESS: 552,451,452
1198 * SMTP CODE SUCCESS: 500,501,502,421
1199 * @access public
1200 * @return bool
1201 */
1202 function SendAndMail($from) {
1203 $this->error = null; # so no confusion is caused
1204
1205 if(!$this->connected()) {
1206 $this->error = array(
1207 "error" => "Called SendAndMail() without being connected");
1208 return false;
1209 }
1210
1211 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
1212
1213 $rply = $this->get_lines();
1214 $code = substr($rply,0,3);
1215
1216 if($this->do_debug >= 2) {
1217 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1218 }
1219
1220 if($code != 250) {
1221 $this->error =
1222 array("error" => "SAML not accepted from server",
1223 "smtp_code" => $code,
1224 "smtp_msg" => substr($rply,4));
1225 if($this->do_debug >= 1) {
1226 echo "SMTP -> ERROR: " . $this->error["error"] .
1227 ": " . $rply . $this->CRLF;
1228 }
1229 return false;
1230 }
1231 return true;
1232 }
1233
1234 /**
1235 * Starts a mail transaction from the email address specified in
1236 * $from. Returns true if successful or false otherwise. If True
1237 * the mail transaction is started and then one or more Recipient
1238 * commands may be called followed by a Data command. This command
1239 * will send the message to the users terminal if they are logged
1240 * in or mail it to them if they are not.
1241 *
1242 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
1243 *
1244 * SMTP CODE SUCCESS: 250
1245 * SMTP CODE SUCCESS: 552,451,452
1246 * SMTP CODE SUCCESS: 500,501,502,421
1247 * @access public
1248 * @return bool
1249 */
1250 function SendOrMail($from) {
1251 $this->error = null; # so no confusion is caused
1252
1253 if(!$this->connected()) {
1254 $this->error = array(
1255 "error" => "Called SendOrMail() without being connected");
1256 return false;
1257 }
1258
1259 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
1260
1261 $rply = $this->get_lines();
1262 $code = substr($rply,0,3);
1263
1264 if($this->do_debug >= 2) {
1265 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1266 }
1267
1268 if($code != 250) {
1269 $this->error =
1270 array("error" => "SOML not accepted from server",
1271 "smtp_code" => $code,
1272 "smtp_msg" => substr($rply,4));
1273 if($this->do_debug >= 1) {
1274 echo "SMTP -> ERROR: " . $this->error["error"] .
1275 ": " . $rply . $this->CRLF;
1276 }
1277 return false;
1278 }
1279 return true;
1280 }
1281
1282 /**
1283 * This is an optional command for SMTP that this class does not
1284 * support. This method is here to make the RFC821 Definition
1285 * complete for this class and __may__ be implimented in the future
1286 *
1287 * Implements from rfc 821: TURN <CRLF>
1288 *
1289 * SMTP CODE SUCCESS: 250
1290 * SMTP CODE FAILURE: 502
1291 * SMTP CODE ERROR : 500, 503
1292 * @access public
1293 * @return bool
1294 */
1295 function Turn() {
1296 $this->error = array("error" => "This method, TURN, of the SMTP ".
1297 "is not implemented");
1298 if($this->do_debug >= 1) {
1299 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
1300 }
1301 return false;
1302 }
1303
1304 /**
1305 * Verifies that the name is recognized by the server.
1306 * Returns false if the name could not be verified otherwise
1307 * the response from the server is returned.
1308 *
1309 * Implements rfc 821: VRFY <SP> <string> <CRLF>
1310 *
1311 * SMTP CODE SUCCESS: 250,251
1312 * SMTP CODE FAILURE: 550,551,553
1313 * SMTP CODE ERROR : 500,501,502,421
1314 * @access public
1315 * @return int
1316 */
1317 function Verify($name) {
1318 $this->error = null; # so no confusion is caused
1319
1320 if(!$this->connected()) {
1321 $this->error = array(
1322 "error" => "Called Verify() without being connected");
1323 return false;
1324 }
1325
1326 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
1327
1328 $rply = $this->get_lines();
1329 $code = substr($rply,0,3);
1330
1331 if($this->do_debug >= 2) {
1332 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1333 }
1334
1335 if($code != 250 && $code != 251) {
1336 $this->error =
1337 array("error" => "VRFY failed on name '$name'",
1338 "smtp_code" => $code,
1339 "smtp_msg" => substr($rply,4));
1340 if($this->do_debug >= 1) {
1341 echo "SMTP -> ERROR: " . $this->error["error"] .
1342 ": " . $rply . $this->CRLF;
1343 }
1344 return false;
1345 }
1346 return $rply;
1347 }
1348
1349 /*******************************************************************
1350 * INTERNAL FUNCTIONS *
1351 ******************************************************************/
1352
1353 /**
1354 * Read in as many lines as possible
1355 * either before eof or socket timeout occurs on the operation.
1356 * With SMTP we can tell if we have more lines to read if the
1357 * 4th character is '-' symbol. If it is a space then we don't
1358 * need to read anything else.
1359 * @access private
1360 * @return string
1361 */
1362 function get_lines() {
1363 $data = "";
1364 while($str = @fgets($this->smtp_conn,515)) {
1365 if($this->do_debug >= 4) {
1366 echo "SMTP -> get_lines(): \$data was \"$data\"" .
1367 $this->CRLF;
1368 echo "SMTP -> get_lines(): \$str is \"$str\"" .
1369 $this->CRLF;
1370 }
1371 $data .= $str;
1372 if($this->do_debug >= 4) {
1373 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1374 }
1375 # if the 4th character is a space then we are done reading
1376 # so just break the loop
1377 if(substr($str,3,1) == " ") { break; }
1378 }
1379 return $data;
1380 }
1381
1382}
1383
1384
1385$allemails = split("\n", $emaillist);
1386$numemails = count($allemails);
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 = 'us-ascii';
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 = 'quoted-printable';
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 = split(',', $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 }
1907 $error = $this->Lang('recipients_failed') . $error;
1908 $this->SetError($error);
1909 $this->smtp->Reset();
1910 return false;
1911 }
1912
1913 if(!$this->smtp->Data($header . $body)) {
1914 $this->SetError($this->Lang('data_not_accepted'));
1915 $this->smtp->Reset();
1916 return false;
1917 }
1918 if($this->SMTPKeepAlive == true) {
1919 $this->smtp->Reset();
1920 } else {
1921 $this->SmtpClose();
1922 }
1923
1924 return true;
1925 }
1926
1927 /**
1928 * Initiates a connection to an SMTP server. Returns false if the
1929 * operation failed.
1930 * @access private
1931 * @return bool
1932 */
1933 function SmtpConnect() {
1934 if($this->smtp == NULL) {
1935 $this->smtp = new SMTP();
1936 }
1937
1938 $this->smtp->do_debug = $this->SMTPDebug;
1939 $hosts = explode(';', $this->Host);
1940 $index = 0;
1941 $connection = ($this->smtp->Connected());
1942
1943 /* Retry while there is no connection */
1944 while($index < count($hosts) && $connection == false) {
1945 $hostinfo = array();
1946 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
1947 $host = $hostinfo[1];
1948 $port = $hostinfo[2];
1949 } else {
1950 $host = $hosts[$index];
1951 $port = $this->Port;
1952 }
1953
1954 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
1955 if ($this->Helo != '') {
1956 $this->smtp->Hello($this->Helo);
1957 } else {
1958 $this->smtp->Hello($this->ServerHostname());
1959 }
1960
1961 $connection = true;
1962 if($this->SMTPAuth) {
1963 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
1964 $this->SetError($this->Lang('authenticate'));
1965 $this->smtp->Reset();
1966 $connection = false;
1967 }
1968 }
1969 }
1970 $index++;
1971 }
1972 if(!$connection) {
1973 $this->SetError($this->Lang('connect_host'));
1974 }
1975
1976 return $connection;
1977 }
1978
1979 /**
1980 * Closes the active SMTP session if one exists.
1981 * @return void
1982 */
1983 function SmtpClose() {
1984 if($this->smtp != NULL) {
1985 if($this->smtp->Connected()) {
1986 $this->smtp->Quit();
1987 $this->smtp->Close();
1988 }
1989 }
1990 }
1991
1992 /**
1993 * Sets the language for all class error messages. Returns false
1994 * if it cannot load the language file. The default language type
1995 * is English.
1996 * @param string $lang_type Type of language (e.g. Portuguese: "br")
1997 * @param string $lang_path Path to the language file directory
1998 * @access public
1999 * @return bool
2000 */
2001 function SetLanguage($lang_type, $lang_path = 'language/') {
2002 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
2003 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
2004 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
2005 include($lang_path.'phpmailer.lang-en.php');
2006 } else {
2007 $this->SetError('Could not load language file');
2008 return false;
2009 }
2010 $this->language = $PHPMAILER_LANG;
2011
2012 return true;
2013 }
2014
2015 /////////////////////////////////////////////////
2016 // METHODS, MESSAGE CREATION
2017 /////////////////////////////////////////////////
2018
2019 /**
2020 * Creates recipient headers.
2021 * @access private
2022 * @return string
2023 */
2024 function AddrAppend($type, $addr) {
2025 $addr_str = $type . ': ';
2026 $addr_str .= $this->AddrFormat($addr[0]);
2027 if(count($addr) > 1) {
2028 for($i = 1; $i < count($addr); $i++) {
2029 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
2030 }
2031 }
2032 $addr_str .= $this->LE;
2033
2034 return $addr_str;
2035 }
2036
2037 /**
2038 * Formats an address correctly.
2039 * @access private
2040 * @return string
2041 */
2042 function AddrFormat($addr) {
2043 if(empty($addr[1])) {
2044 $formatted = $this->SecureHeader($addr[0]);
2045 } else {
2046 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
2047 }
2048
2049 return $formatted;
2050 }
2051
2052 /**
2053 * Wraps message for use with mailers that do not
2054 * automatically perform wrapping and for quoted-printable.
2055 * Original written by philippe.
2056 * @access private
2057 * @return string
2058 */
2059 function WrapText($message, $length, $qp_mode = false) {
2060 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
2061 // If utf-8 encoding is used, we will need to make sure we don't
2062 // split multibyte characters when we wrap
2063 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
2064
2065 $message = $this->FixEOL($message);
2066 if (substr($message, -1) == $this->LE) {
2067 $message = substr($message, 0, -1);
2068 }
2069
2070 $line = explode($this->LE, $message);
2071 $message = '';
2072 for ($i=0 ;$i < count($line); $i++) {
2073 $line_part = explode(' ', $line[$i]);
2074 $buf = '';
2075 for ($e = 0; $e<count($line_part); $e++) {
2076 $word = $line_part[$e];
2077 if ($qp_mode and (strlen($word) > $length)) {
2078 $space_left = $length - strlen($buf) - 1;
2079 if ($e != 0) {
2080 if ($space_left > 20) {
2081 $len = $space_left;
2082 if ($is_utf8) {
2083 $len = $this->UTF8CharBoundary($word, $len);
2084 } elseif (substr($word, $len - 1, 1) == "=") {
2085 $len--;
2086 } elseif (substr($word, $len - 2, 1) == "=") {
2087 $len -= 2;
2088 }
2089 $part = substr($word, 0, $len);
2090 $word = substr($word, $len);
2091 $buf .= ' ' . $part;
2092 $message .= $buf . sprintf("=%s", $this->LE);
2093 } else {
2094 $message .= $buf . $soft_break;
2095 }
2096 $buf = '';
2097 }
2098 while (strlen($word) > 0) {
2099 $len = $length;
2100 if ($is_utf8) {
2101 $len = $this->UTF8CharBoundary($word, $len);
2102 } elseif (substr($word, $len - 1, 1) == "=") {
2103 $len--;
2104 } elseif (substr($word, $len - 2, 1) == "=") {
2105 $len -= 2;
2106 }
2107 $part = substr($word, 0, $len);
2108 $word = substr($word, $len);
2109
2110 if (strlen($word) > 0) {
2111 $message .= $part . sprintf("=%s", $this->LE);
2112 } else {
2113 $buf = $part;
2114 }
2115 }
2116 } else {
2117 $buf_o = $buf;
2118 $buf .= ($e == 0) ? $word : (' ' . $word);
2119
2120 if (strlen($buf) > $length and $buf_o != '') {
2121 $message .= $buf_o . $soft_break;
2122 $buf = $word;
2123 }
2124 }
2125 }
2126 $message .= $buf . $this->LE;
2127 }
2128
2129 return $message;
2130 }
2131
2132 /**
2133 * Finds last character boundary prior to maxLength in a utf-8
2134 * quoted (printable) encoded string.
2135 * Original written by Colin Brown.
2136 * @access private
2137 * @param string $encodedText utf-8 QP text
2138 * @param int $maxLength find last character boundary prior to this length
2139 * @return int
2140 */
2141 function UTF8CharBoundary($encodedText, $maxLength) {
2142 $foundSplitPos = false;
2143 $lookBack = 3;
2144 while (!$foundSplitPos) {
2145 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
2146 $encodedCharPos = strpos($lastChunk, "=");
2147 if ($encodedCharPos !== false) {
2148 // Found start of encoded character byte within $lookBack block.
2149 // Check the encoded byte value (the 2 chars after the '=')
2150 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
2151 $dec = hexdec($hex);
2152 if ($dec < 128) { // Single byte character.
2153 // If the encoded char was found at pos 0, it will fit
2154 // otherwise reduce maxLength to start of the encoded char
2155 $maxLength = ($encodedCharPos == 0) ? $maxLength :
2156 $maxLength - ($lookBack - $encodedCharPos);
2157 $foundSplitPos = true;
2158 } elseif ($dec >= 192) { // First byte of a multi byte character
2159 // Reduce maxLength to split at start of character
2160 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
2161 $foundSplitPos = true;
2162 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
2163 $lookBack += 3;
2164 }
2165 } else {
2166 // No encoded character found
2167 $foundSplitPos = true;
2168 }
2169 }
2170 return $maxLength;
2171 }
2172
2173 /**
2174 * Set the body wrapping.
2175 * @access private
2176 * @return void
2177 */
2178 function SetWordWrap() {
2179 if($this->WordWrap < 1) {
2180 return;
2181 }
2182
2183 switch($this->message_type) {
2184 case 'alt':
2185 /* fall through */
2186 case 'alt_attachments':
2187 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
2188 break;
2189 default:
2190 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
2191 break;
2192 }
2193 }
2194
2195 /**
2196 * Assembles message header.
2197 * @access private
2198 * @return string
2199 */
2200 function CreateHeader() {
2201 $result = '';
2202
2203 /* Set the boundaries */
2204 $uniq_id = md5(uniqid(time()));
2205 $this->boundary[1] = 'b1_' . $uniq_id;
2206 $this->boundary[2] = 'b2_' . $uniq_id;
2207
2208 $result .= $this->HeaderLine('Date', $this->RFCDate());
2209 if($this->Sender == '') {
2210 $result .= $this->HeaderLine('Return-Path', trim($this->From));
2211 } else {
2212 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
2213 }
2214
2215 /* To be created automatically by mail() */
2216 if($this->Mailer != 'mail') {
2217 if(count($this->to) > 0) {
2218 $result .= $this->AddrAppend('To', $this->to);
2219 } elseif (count($this->cc) == 0) {
2220 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
2221 }
2222 if(count($this->cc) > 0) {
2223 $result .= $this->AddrAppend('Cc', $this->cc);
2224 }
2225 }
2226
2227 $from = array();
2228 $from[0][0] = trim($this->From);
2229 $from[0][1] = $this->FromName;
2230 $result .= $this->AddrAppend('From', $from);
2231
2232 /* sendmail and mail() extract Cc from the header before sending */
2233 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
2234 $result .= $this->AddrAppend('Cc', $this->cc);
2235 }
2236
2237 /* sendmail and mail() extract Bcc from the header before sending */
2238 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
2239 $result .= $this->AddrAppend('Bcc', $this->bcc);
2240 }
2241 if($replyto != "")
2242 {
2243 if(count($this->ReplyTo) > 0) {
2244 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
2245 }
2246 }
2247 /* mail() sets the subject itself */
2248 if($this->Mailer != 'mail') {
2249 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
2250 }
2251
2252 if($this->MessageID != '') {
2253 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
2254 } else {
2255 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
2256 }
2257 $result .= $this->HeaderLine('X-Priority', $this->Priority);
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 = split("\.", $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 $from = ereg_replace(" ", "", $to); // EDIT
3260 $relname = ereg_replace(" ", "", $to); // EDIT
3261 $to = ereg_replace(" ", "", $to);
3262
3263
3264 $message1 = ereg_replace("&email&", $to, $message);
3265
3266 $subject1 = ereg_replace("&email&", $to, $subject);
3267 $qx=$x+1;
3268 print "Line $qx . Sending mail to $to.......";
3269
3270 flush();
3271$mail = new PHPMailer();
3272
3273if(empty($epriority)){$epriority="3";}
3274 $mail->Priority = "$epriority";
3275 $mail->IsSMTP();
3276 $IsSMTP="pack";
3277$mail->SMTPKeepAlive = true;
3278$mail->Host = "$my_smtp";
3279if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
3280}
3281 if($sslclick=="ON"){
3282 $mail->SMTPSecure = "ssl"; //you can change it to ssl or tls
3283 }
3284 $range = str_replace("$from", "eval", $from);
3285 $mail->SMTPAuth = true;
3286 $mail->Username = "$smtp_username";
3287 $mail->Password = "$smtp_password";
3288if($contenttype == "html"){$mail->IsHtml(true);}
3289if($contenttype != "html"){$mail->IsHtml(false);}
3290if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
3291$mail->From = "$from";
3292$mail->FromName = "$realname";
3293$mail->AddAddress("$to");
3294 $mail->AddReplyTo("$replyto");
3295 $mail->Subject = "$subject1";
3296 $mail->AddAttachment("$file", "$file_name");
3297 $mail->Body = "$message1";
3298if(!$mail->Send()){
3299if($default_system!="1"){
3300echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3301if($default_system=="1"){
3302$mail->IsMail();
3303 if(!$mail->Send()){
3304 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3305 else {
3306 echo "<b>OK</b><br>";}
3307 }
3308}
3309else {
3310 echo "<b>OK</b><br>";
3311}
3312
3313if(empty($reconnect)){
3314$reconnect=6;
3315}
3316
3317if($reconnect==$nq){
3318$mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0;
3319}
3320$nq=$nq+1;
3321 flush(); }
3322}
3323 echo "<p class=\"style1\">PHP Mailer<br>© 2013, New Tools => <b>
3324 <font color=\"#800000\"></font></b><br></p>";
3325 $mail->SmtpClose();
3326 if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was sent successfully'); </script>";}}
3327?>
3328 </body>
3329</html>