Advertisement
Guest User

Untitled

a guest
Jun 26th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. <?php
  2. function get_data($smtp_conn)
  3. {
  4. $data="";
  5. while($str = fgets($smtp_conn,515))
  6. {
  7. $data .= $str;
  8. if(substr($str,3,1) == " ") { break; }
  9. }
  10. return $data;
  11. }
  12. function SendMail($config)
  13. {
  14. if(!isset($config['priority']))
  15. $config['priority']=3;
  16.  
  17. $header="Date: ".date("D, j M Y G:i:s")." +0700rn";
  18. $header.="From: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode("{$config['from_title']}")))."?= <{$config['from']}>rn";
  19. $header.="X-Mailer: The Bat! (v3.99.3) Professionalrn";
  20. $header.="Reply-To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode("{$config['from_title']}")))."?= <{$config['from']}>rn";
  21. $header.="X-Priority: {$config['priority']}rn";
  22. $header.="Message-ID: <172562218.".date("YmjHis")."@microsoft.com>rn";
  23. $header.="To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($config['to_title'])))."?= <{$config['to']}>rn";
  24. $header.="Subject: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($config['subject'])))."?=rn";
  25. $header.="MIME-Version: 1.0rn";
  26. $header.="Content-Type: multipart/mixed; boundary="----------A4D921C2D10D7DB"rn";
  27.  
  28. $attach=NULL;
  29. $code_file=NULL;
  30. if(isset($config['attach_file']))
  31. {
  32. if(file_exists($config['attach_file']))
  33. {
  34. $fp = fopen($config['attach_file'], "rb");
  35. $code_file = chunk_split(base64_encode(fread($fp, filesize($config['attach_file']))));
  36. fclose($fp);
  37. $attach.="------------A4D921C2D10D7DB
  38. Content-Type: application/octet-stream; name="".basename($config['attach_file']).""
  39. Content-transfer-encoding: base64
  40. Content-Disposition: attachment; filename="".basename($config['attach_file']).""
  41.  
  42. {$code_file}";
  43. }
  44. }
  45.  
  46. if(isset($config['attach_dir']))
  47. {
  48. $dir = $config['attach_dir'];
  49. if (is_dir($dir))
  50. if ($dh = opendir($dir))
  51. {
  52. while (($file = readdir($dh)) !== false)
  53. if($file!="." && $file!="..")
  54. {
  55. $fp = fopen($dir.$file, "rb");
  56. $code_file = chunk_split(base64_encode(fread($fp, filesize($dir.$file))));
  57. fclose($fp);
  58. $attach.="------------A4D921C2D10D7DB
  59. Content-Type: application/octet-stream; name="".basename($dir.$file).""
  60. Content-transfer-encoding: base64
  61. Content-Disposition: attachment; filename="".basename($dir.$file).""
  62.  
  63. {$code_file}";
  64.  
  65. }
  66. closedir($dh);
  67. }
  68.  
  69. }
  70.  
  71. if(isset($config['html_file']))
  72. {
  73. if(file_exists($config['html_file']))
  74. {
  75. $filename = $config['html_file'];
  76. $handle = fopen($filename, "r");
  77. $contents = fread($handle, filesize($filename));
  78. fclose($handle);
  79. $config['html'].=$contents;
  80. }
  81. }
  82.  
  83. $text="------------A4D921C2D10D7DB
  84. Content-Type: text/html; charset=windows-1251
  85. Content-Transfer-Encoding: 8bit
  86.  
  87. {$config['html']}
  88.  
  89. {$attach}rn
  90.  
  91.  
  92. ------------A4D921C2D10D7DB--
  93. ";
  94.  
  95. $smtp_conn = fsockopen($config['server'], $config['port'],$errno, $errstr, 10);
  96. if(!$smtp_conn) {print "Connect is fail"; fclose($smtp_conn); exit;}
  97. $data = get_data($smtp_conn);
  98. fputs($smtp_conn,"EHLO ".time()."rn");
  99. $code = substr(get_data($smtp_conn),0,3);
  100. if($code != 250) {print "Command fail EHLO"; fclose($smtp_conn); exit;}
  101.  
  102. if(isset($config['login']))
  103. {
  104. fputs($smtp_conn,"AUTH LOGINrn");
  105. $code = substr(get_data($smtp_conn),0,3);
  106. if($code != 334) {print "Command fail AUTH LOGIN"; fclose($smtp_conn); exit;}
  107.  
  108. fputs($smtp_conn,base64_encode($config['login'])."rn");
  109. $code = substr(get_data($smtp_conn),0,3);
  110. if($code != 334) {print "Login is not exists"; fclose($smtp_conn); exit;}
  111.  
  112. fputs($smtp_conn,base64_encode($config['password'])."rn");
  113. $code = substr(get_data($smtp_conn),0,3);
  114. if($code != 235) {print "Password is not correct"; fclose($smtp_conn); exit;}
  115. }
  116.  
  117. $size_msg=strlen($header."rn".$text);
  118.  
  119. fputs($smtp_conn,"MAIL FROM:<{$config['from']}> SIZE=".$size_msg."rn");
  120.  
  121. $code = substr(get_data($smtp_conn),0,3);
  122. if($code != 250) {print "Command fail MAIL FROM"; fclose($smtp_conn); exit;}
  123.  
  124. fputs($smtp_conn,"RCPT TO:<{$config['to']}>rn");
  125. $code = substr(get_data($smtp_conn),0,3);
  126. if($code != 250 AND $code != 251) {print "Command fail RCPT TO"; fclose($smtp_conn); exit;}
  127.  
  128. fputs($smtp_conn,"DATArn");
  129. $code = substr(get_data($smtp_conn),0,3);
  130. if($code != 354) {print "Command fail DATA"; fclose($smtp_conn); exit;}
  131.  
  132. fputs($smtp_conn,$header."rn".$text."rn.rn");
  133. $code = substr(get_data($smtp_conn),0,3);
  134. if($code != 250) {print "Send main error"; fclose($smtp_conn); exit;}
  135.  
  136. fputs($smtp_conn,"QUITrn");
  137. fclose($smtp_conn);
  138.  
  139. if(@$config['debug']=="on")
  140. {
  141. echo "<pre><code>";
  142. print_r($config);
  143. echo "</code></pre>";
  144.  
  145. echo "Attach file:<br>{$attach}";
  146. }
  147. else
  148. echo "200: OK";
  149. }
  150. /*
  151. server - smtp.mail.ru
  152. port - 25
  153.  
  154. login - barsukov.vv@mail.ru
  155. passowrd - *********
  156.  
  157. from - admin@yandex.ru
  158. from_title - Администрация Яндекс.ру
  159.  
  160. to - target@domain.net
  161. to_title - Target
  162.  
  163. subject - Spam
  164. html - <div style='font-size:36pt;'>html</div>
  165. html_file - html/plain.html
  166.  
  167. priority : важность
  168. 1 - высокая
  169. 3 - обычная(по умолчанию)
  170. 5 - низкая
  171.  
  172. attach_file - image.jpg
  173. attach_dir - image/
  174.  
  175. debug - De`жук(on)
  176. */
  177. SendMail(array("from"=>"admin@yandex.ru", "from_title"=>"Администрация Yandex.ru", "to"=>"barsukov.vv@mail.ru", "to_title"=>"Барсуков Владимир", "server"=>"mail-omsk.omsk.srsh.ru", "port"=>25, "subject"=>time(), "html"=>"html", "attach_file"=>"test/mazda.jpg", "attach_dir"=>"test/", "html_file"=>"test.html", "priority"=>"1", "debug"=>"on"));
  178. ?>
  179.  
  180. <?php
  181. mail("to@somewhere.ru", "Subject", "message");
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement