Guest User

mailer.php

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