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