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