email.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?
  2. //email ("lord_rimmon@mail.ru", "ggg", "lol");
  3. function get_data($smtp_conn)
  4. {
  5. $data="";
  6. while($str = fgets($smtp_conn,515))
  7. {
  8. $data .= $str;
  9. if(substr($str,3,1) == " ") { break; }
  10. }
  11. return $data;
  12. }
  13. function email($to, $subj, $text)
  14. {
  15. $smtp = "pvlt.ru";
  16. $name = "Dark Matter";
  17. $send_mail = "info@dmatter.net";
  18. $send_host = "dmatter.net";
  19. $smtp_user = "info@dmatter.net";
  20. $smtp_pass = "Death12";
  21. $header="Date: ".date("D, j M Y G:i:s")." +0700\r\n";
  22. $header.="From: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($name)))."?= <".$send_mail.">\r\n";
  23. $header.="X-Mailer: The Bat! (v3.99.3) Professional\r\n";
  24. $header.="Reply-To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($name)))."?= <".$send_mail.">\r\n";
  25. $header.="X-Priority: 3 (Normal)\r\n";
  26. $header.="Message-ID: <172562218.".date("YmjHis")."@".$send_host.">\r\n";
  27. $header.="To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($to)))."?= <".$to.">\r\n"; //to name
  28. $header.="Subject: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode($subj)))."?=\r\n";
  29. $header.="MIME-Version: 1.0\r\n";
  30. $header.="Content-Type: text/plain; charset=windows-1251\r\n";
  31. $header.="Content-Transfer-Encoding: 8bit\r\n";
  32. $smtp_conn = fsockopen($smtp, 25,$errno, $errstr, 10);
  33. if(!$smtp_conn) {print "ñîåäèíåíèå ñ ñåðâåðîì íå ïðîøëî "; fclose($smtp_conn); return false; exit;}
  34. $data = get_data($smtp_conn);
  35. fputs($smtp_conn,"EHLO ".$smtp."\r\n");
  36. $code = substr(get_data($smtp_conn),0,3);
  37. if($code != 250) {print "îøèáêà ïðèâåòñâèÿ EHLO"; fclose($smtp_conn); return false; exit;}
  38. fputs($smtp_conn,"AUTH LOGIN\r\n");
  39. $code = substr(get_data($smtp_conn),0,3);
  40. if($code != 334) {print "ñåðâåð íå ðàçðåøèë íà÷àòü àâòîðèçàöèþ "; fclose($smtp_conn); return false; exit;}
  41. fputs($smtp_conn,base64_encode($smtp_user)."\r\n");
  42. $code = substr(get_data($smtp_conn),0,3);
  43. if($code != 334) {print "îøèáêà äîñòóïà ê òàêîìó þçåðó "; fclose($smtp_conn); return false; exit;}
  44. fputs($smtp_conn,base64_encode($smtp_pass)."\r\n");
  45. $code = substr(get_data($smtp_conn),0,3);
  46. if($code != 235) {print "íåïðàâèëüíûé ïàðîëü "; fclose($smtp_conn); return false; exit;}
  47. fputs($smtp_conn,"MAIL FROM:".$send_mail."\r\n");
  48. $code = substr(get_data($smtp_conn),0,3);
  49. if($code != 250) {print "ñåðâåð îòêàçàë â êîìàíäå MAIL FROM "; fclose($smtp_conn); return false; exit;}
  50. fputs($smtp_conn,"RCPT TO:".$to."\r\n");
  51. $code = substr(get_data($smtp_conn),0,3);
  52. if($code != 250 AND $code != 251) {print "Ñåðâåð íå ïðèíÿë êîìàíäó RCPT TO "; fclose($smtp_conn); return false; exit;}
  53. fputs($smtp_conn,"DATA\r\n");
  54. $code = substr(get_data($smtp_conn),0,3);
  55. if($code != 354) {print "ñåðâåð íå ïðèíÿë DATA "; fclose($smtp_conn); return false; exit;}
  56. fputs($smtp_conn,$header."\r\n".$text."\r\n.\r\n");
  57. $code = substr(get_data($smtp_conn),0,3);
  58. if($code != 250) {print "îøèáêà îòïðàâêè ïèñüìà "; fclose($smtp_conn); return false; exit;}
  59. fputs($smtp_conn,"QUIT\r\n");
  60. fclose($smtp_conn);
  61. return true;
  62. }
  63. ?>