Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. <?php
  2. $true = true;
  3. class mail
  4. {
  5. public static $site_name = "";
  6. public static $from = "";
  7. public static $to = "";
  8. public static $subject = "";
  9. public static $message = "";
  10. public static $header = "";
  11. public static $additional_parameters = null;
  12. public static $error = "";
  13. public static $bcc = array ();
  14. public static $mail_headers = "";
  15. public static $html_mail = 0;
  16. public static $charset = 'UTF-8';
  17.  
  18. public static $smtp_fp = false;
  19. public static $smtp_msg = "";
  20. public static $smtp_port = "";
  21. public static $smtp_host = "localhost";
  22. public static $smtp_user = "";
  23. public static $smtp_pass = "";
  24. public static $smtp_code = "";
  25. public static $smtp_mail = "";
  26. public static $smtp_helo = "";
  27. public static $send_error = false;
  28.  
  29. public static $eol = "\n";
  30.  
  31. public static $mail_method = 'aviras';
  32.  
  33. public static function gamepl_mail ()
  34. {
  35. global $conf;
  36. self::$mail_method = $conf['mail_type'];
  37.  
  38. self::$from = $conf['mail'];
  39. self::$site_name = $_SERVER['HTTP_HOST'];
  40. self::$smtp_mail = trim($conf['smtp']['mail']) ? trim($conf['smtp']['mail']) : '';
  41. self::$smtp_helo = trim($conf['smtp']['helo']) ? trim($conf['smtp']['helo']) : 'HELO';
  42.  
  43. self::$smtp_host = $conf['smtp']['server'];
  44. self::$smtp_port = intval( $conf['smtp']['port'] );
  45. self::$smtp_user = $conf['smtp']['mail'];
  46. self::$smtp_pass = $conf['smtp']['pass'];
  47.  
  48. self::$html_mail = true;
  49. }
  50.  
  51. public static function compile_headers ()
  52. {
  53.  
  54. self::$subject = "=?" . self::$charset . "?b?" . base64_encode ( self::$subject ) . "?=";
  55.  
  56. if ( self::$site_name ) {
  57. $from = "=?" . self::$charset . "?b?" . base64_encode ( self::$site_name ) . "?=";
  58. } else {
  59. $from = "";
  60. }
  61.  
  62. if ( self::$html_mail ) {
  63. self::$mail_headers .= "MIME-Version: 1.0" . self::$eol;
  64. self::$mail_headers .= "Content-type: text/html; charset=\"" . self::$charset . "\"" . self::$eol;
  65. } else {
  66. self::$mail_headers .= "MIME-Version: 1.0" . self::$eol;
  67. self::$mail_headers .= "Content-type: text/plain; charset=\"" . self::$charset . "\"" . self::$eol;
  68. }
  69.  
  70. if ( self::$mail_method != 'smtp' ) {
  71.  
  72. if ( count ( self::$bcc ) ) {
  73. self::$mail_headers .= "Bcc: " . implode ( "," , self::$bcc ) . self::$eol;
  74. }
  75.  
  76. } else {
  77.  
  78. self::$mail_headers .= "Subject: " . self::$subject . self::$eol;
  79.  
  80. if ( self::$to ) {
  81.  
  82. self::$mail_headers .= "To: " . self::$to . self::$eol;
  83. }
  84.  
  85. }
  86.  
  87. self::$mail_headers .= "From: \"" . $from . "\" <" . self::$from . ">" . self::$eol;
  88.  
  89. self::$mail_headers .= "Return-Path: <" . self::$from . ">" . self::$eol;
  90. self::$mail_headers .= "X-Priority: 3" . self::$eol;
  91. self::$mail_headers .= "X-MSMail-Priority: Normal" . self::$eol;
  92. self::$mail_headers .= "X-Mailer: DLE CMS PHP" . self::$eol;
  93.  
  94. }
  95.  
  96. public static function send ( $to , $subject , $message )
  97. {
  98. self::gamepl_mail ();
  99. self::$to = preg_replace ( "/[ \t]+/" , "" , $to );
  100. self::$from = preg_replace ( "/[ \t]+/" , "" , self::$from );
  101.  
  102. self::$to = preg_replace ( "/,,/" , "," , self::$to );
  103. self::$from = preg_replace ( "/,,/" , "," , self::$from );
  104.  
  105. if ( self::$mail_method != 'smtp' ) {
  106. self::$to = preg_replace ( "#\#\[\]'\"\(\):;/\$!�%\^&\*\{\}#" , "" , self::$to );
  107. } else {
  108. self::$to = '<' . preg_replace ( "#\#\[\]'\"\(\):;/\$!�%\^&\*\{\}#" , "" , self::$to ) . '>';
  109. }
  110.  
  111.  
  112. self::$from = preg_replace ( "#\#\[\]'\"\(\):;/\$!�%\^&\*\{\}#" , "" , self::$from );
  113.  
  114. self::$subject = $subject;
  115. self::$message = $message;
  116.  
  117. self::$message = str_replace ( "\r" , "" , self::$message );
  118.  
  119. self::compile_headers ();
  120.  
  121. if ( ( self::$to ) and ( self::$from ) and ( self::$subject ) ) {
  122. if ( self::$mail_method == 'mail' ) {
  123.  
  124. if ( ! @mail ( self::$to , self::$subject , self::$message , self::$mail_headers , self::$additional_parameters ) ) {
  125.  
  126. if ( ! @mail ( self::$to , self::$subject , self::$message , self::$mail_headers ) ) {
  127.  
  128. self::$smtp_msg = "PHP Mail Error.";
  129. self::$send_error = true;
  130.  
  131. }
  132.  
  133. }
  134. } elseif(self::$mail_method == 'smtp') {
  135. self::smtp_send ();
  136. } else {
  137. self::aviras_send ($to , $subject , $message);
  138. }
  139.  
  140. }
  141.  
  142. self::$mail_headers = "";
  143.  
  144. }
  145. public static function aviras_send ( $to , $subject , $message )
  146. {
  147. global $conf;
  148. $d['mail'] = str_replace('/','-',base64_encode($to));
  149. $d['title'] = str_replace('/','-',base64_encode($subject));
  150. $d['msg'] = str_replace('/','-',base64_encode($message));
  151. $d['send'] = str_replace('/','-',base64_encode( $conf['mail']));
  152. $d['domain'] = str_replace('/','-',base64_encode( $conf['domain']));
  153. $data = str_replace('/','-',base64_encode(json_encode($d,JSON_UNESCAPED_UNICODE)));
  154. @file_get_contents('http://gamepl.ru/mailes/send/'.api::$token.'/?body='.$data);
  155. }
  156. public static function smtp_get_line ()
  157. {
  158. self::$smtp_msg = "";
  159.  
  160. while ( $line = fgets ( self::$smtp_fp , 515 ) ) {
  161. self::$smtp_msg .= $line;
  162.  
  163. if ( substr ( $line , 3 , 1 ) == " " ) {
  164. break;
  165. }
  166. }
  167. }
  168.  
  169. public static function smtp_send ()
  170. {
  171. ini_set ( 'default_socket_timeout' , '1' );
  172. self::$smtp_fp = @fsockopen ( self::$smtp_host , intval ( self::$smtp_port ) , $errno , $errstr , 30 );
  173.  
  174. if ( ! self::$smtp_fp ) {
  175. self::smtp_error ( "Could not open a socket to the SMTP server" );
  176.  
  177. return;
  178. }
  179.  
  180. self::smtp_get_line ();
  181.  
  182. self::$smtp_code = substr ( self::$smtp_msg , 0 , 3 );
  183.  
  184. if ( self::$smtp_code == 220 ) {
  185. $data = self::smtp_crlf_encode ( self::$mail_headers . "\n" . self::$message );
  186.  
  187. self::smtp_send_cmd ( self::$smtp_helo . " " . self::$smtp_host );
  188.  
  189. if ( self::$smtp_code != 250 ) {
  190. self::smtp_error ( self::$smtp_helo . " error" );
  191.  
  192. return;
  193. }
  194.  
  195. if ( self::$smtp_user and self::$smtp_pass ) {
  196. self::smtp_send_cmd ( "AUTH LOGIN" );
  197.  
  198. if ( self::$smtp_code == 334 ) {
  199. self::smtp_send_cmd ( base64_encode ( self::$smtp_user ) );
  200.  
  201. if ( self::$smtp_code != 334 ) {
  202. self::smtp_error ( "Username not accepted from the server" );
  203.  
  204. return;
  205. }
  206.  
  207. self::smtp_send_cmd ( base64_encode ( self::$smtp_pass ) );
  208.  
  209. if ( self::$smtp_code != 235 ) {
  210. self::smtp_error ( "Password not accepted from the SMTP server" );
  211.  
  212. return;
  213. }
  214. } else {
  215. self::smtp_error ( "This SMTP server does not support authorisation" );
  216.  
  217. return;
  218. }
  219. }
  220.  
  221. if ( ! self::$smtp_mail ) {
  222. self::$smtp_mail = self::$from;
  223. }
  224.  
  225. self::smtp_send_cmd ( "MAIL FROM:<" . self::$smtp_mail . ">" );
  226.  
  227. if ( self::$smtp_code != 250 ) {
  228. self::smtp_error ( "Incorrect FROM address: self::smtp_mail" );
  229.  
  230. return;
  231. }
  232.  
  233. $to_array = array ( self::$to );
  234.  
  235. if ( count ( self::$bcc ) ) {
  236. foreach ( self::$bcc as $bcc ) {
  237. if ( preg_match ( "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/" , str_replace ( " " , "" , $bcc ) ) ) {
  238. $to_array[ ] = "<" . $bcc . ">";
  239. }
  240. }
  241. }
  242.  
  243. foreach ( $to_array as $to_email ) {
  244. self::smtp_send_cmd ( "RCPT TO:" . $to_email );
  245.  
  246. if ( self::$smtp_code != 250 ) {
  247. self::smtp_error ( "Incorrect email address: $to_email" );
  248.  
  249. return;
  250. break;
  251. }
  252. }
  253.  
  254. self::smtp_send_cmd ( "DATA" );
  255.  
  256. if ( self::$smtp_code == 354 ) {
  257. fputs ( self::$smtp_fp , $data . "\r\n" );
  258. } else {
  259. self::smtp_error ( "Error on write to SMTP server" );
  260.  
  261. return;
  262. }
  263.  
  264. self::smtp_send_cmd ( "." );
  265.  
  266. if ( self::$smtp_code != 250 ) {
  267. self::smtp_error ( "Error on send mail" );
  268.  
  269. return;
  270. }
  271.  
  272. self::smtp_send_cmd ( "quit" );
  273.  
  274. if ( self::$smtp_code != 221 ) {
  275. self::smtp_error ( "Error on quit" );
  276.  
  277. return;
  278. }
  279.  
  280. @fclose ( self::$smtp_fp );
  281. } else {
  282. self::smtp_error ( "SMTP service unaviable" );
  283.  
  284. return;
  285. }
  286. }
  287.  
  288. public static function smtp_send_cmd ( $cmd )
  289. {
  290. self::$smtp_msg = "";
  291. self::$smtp_code = "";
  292.  
  293. fputs ( self::$smtp_fp , $cmd . "\r\n" );
  294.  
  295. self::smtp_get_line ();
  296.  
  297. self::$smtp_code = substr ( self::$smtp_msg , 0 , 3 );
  298.  
  299. return self::$smtp_code == "" ? false : true;
  300. }
  301.  
  302. public static function smtp_error ( $err = "" )
  303. {
  304. self::$smtp_msg = $err;
  305. self::$send_error = true;
  306.  
  307. return;
  308. }
  309.  
  310. public static function smtp_crlf_encode ( $data )
  311. {
  312. $data .= "\n";
  313. $data = str_replace ( "\n" , "\r\n" , str_replace ( "\r" , "" , $data ) );
  314. $data = str_replace ( "\n.\r\n" , "\n. \r\n" , $data );
  315.  
  316. return $data;
  317. }
  318. }
  319.  
  320. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement