Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.26 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. define(ROOT, trim(__FILE__, 'sender.php'));
  4.  
  5. class Sender {
  6.  
  7. protected $telegram, $config, $date;
  8.  
  9. public function __construct() {
  10. require_once('recaptchalib.php');
  11.  
  12. // Get a key from https://www.google.com/recaptcha/admin/create
  13. $publickey = "6Le00iQUAAAAAONEMEAPA0CdPrYEi1X842_NO6Bt";
  14. $privatekey = "6Le00iQUAAAAAF2YIYSzrrA43MtAYQ2CwXROyzou";
  15.  
  16. # the response from reCAPTCHA
  17. $resp = null;
  18. # the error code from reCAPTCHA, if any
  19. $error = null;
  20.  
  21. # was there a reCAPTCHA response?
  22. if ($_POST["recaptcha_response_field"]) {
  23. $resp = recaptcha_check_answer ($privatekey,
  24. $_SERVER["REMOTE_ADDR"],
  25. $_POST["recaptcha_challenge_field"],
  26. $_POST["recaptcha_response_field"]);
  27.  
  28. if ($resp->is_valid) {
  29. $config = $this->config('config.ini');
  30.  
  31.  
  32. $date = new DateTime;
  33. $date->setTimezone(new DateTimeZone($config['timezone']));
  34.  
  35. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ? true : false;
  36. //if(!$this->ajax) {
  37. //die('Access danied');
  38. //}
  39.  
  40. //var_dump($this->config);
  41.  
  42. if(isset($_POST['action']) and $_POST['action'] === 'sendMail') {
  43.  
  44. $name = isset($_POST['fio']) ? $_POST['fio'] : 'Не указано';
  45. $phone = isset($_POST['phone']) ? $_POST['phone'] : 'Не указано';
  46. $email = isset($_POST['email']) ? $_POST['email'] : 'Не указано';
  47. $deadLine = isset($_POST['deadLine']) ? $_POST['deadLine'] : 'Не указано';
  48. $description = isset($_POST['description']) ? $_POST['description'] : 'Не указано';
  49. $pages = isset($_POST['pagesAll']) ? $_POST['pagesAll'] : 'Не указано';
  50. $predmet = isset($_POST['predmet']) ? $_POST['predmet'] : 'Не указано';
  51. $text = isset($_POST['text']) ? $_POST['text'] : 'Не указано';
  52. $typejob = isset($_POST['typejob']) ? $_POST['typejob'] : 'Не указано';
  53.  
  54. $body =
  55. 'На сайте ' . $config['home_title'] . " было отправлено сообщение\n\n\n" .
  56. 'Имя: ' . $name . "\n" .
  57. 'Контакты: email - ' . $email . " / телефон - " . $phone . "\n" .
  58. 'Вид работы: ' . $typejob . "\n" .
  59. 'Предмет: ' . $predmet . "\n" .
  60. 'Тема работы: ' . $description . "\n" .
  61. 'Кол-во страниц: ' . $pages . "\n" .
  62. 'Сроки сдачи: ' . $deadLine . "\n" .
  63. 'Доп. информация: ' . $text . "\n\n\n" .
  64. 'Отправлено в: ' . $date->format('Y-m-d H:i:s') . "\n";
  65.  
  66. $mail = new Mailer($config);
  67. $mail->from = $_POST['email'];
  68.  
  69. $mail->send($config['admin_mail'], $typejob . " : " . $predmet, $body);
  70.  
  71. if($mail->send_error) {
  72. echo json_encode(array('status' => 'error', 'message' => $mail->smtp_msg));
  73. } else {
  74. echo json_encode(array('status' => 'success', 'message' => 'Сообщение успешно отправлено'));
  75. $telegram = new Telegram($config['token']);
  76. $telegram->sendMessage(array('chat_id' => $config['chat_id'], 'text' => $body));
  77. if(isset($config['chat_id2']) and !empty($config['chat_id2'])) {
  78. $telegram->sendMessage(array('chat_id' => $config['chat_id2'], 'text' => $body));
  79. }
  80.  
  81. }
  82. }
  83. } else {
  84. # set the error code so that we can display it
  85. $error = $resp->error;
  86. }
  87.  
  88. else {
  89. echo json_encode(array('status' => 'error', 'message' => 'Введите каптчу'));
  90. }
  91.  
  92. }
  93.  
  94. protected function config($file) {
  95. if(file_exists(ROOT . $file)) {
  96. return parse_ini_file(ROOT . $file);
  97. } else {
  98. die('Config file not found');
  99. }
  100. }
  101. }
  102.  
  103. class Telegram {
  104.  
  105. private $bot_id = "";
  106. private $data = array();
  107. private $updates = array();
  108.  
  109. public function __construct($bot_id) {
  110. $this->bot_id = $bot_id;
  111. $this->data = $this->getData();
  112. }
  113.  
  114. public function endpoint($api, array $content, $post = true) {
  115. $url = 'https://api.telegram.org/bot' . $this->bot_id . '/' . $api;
  116. if ($post)
  117. $reply = $this->sendAPIRequest($url, $content);
  118. else
  119. $reply = $this->sendAPIRequest($url, array(), false);
  120. return json_decode($reply, true);
  121. }
  122.  
  123. public function getMe() {
  124. return $this->endpoint("getMe", array(), false);
  125. }
  126.  
  127. public function respondSuccess() {
  128. http_response_code(200);
  129. return json_encode(array("status" => "success"));
  130. }
  131.  
  132. public function sendMessage(array $content) {
  133. return $this->endpoint("sendMessage", $content);
  134. }
  135.  
  136. public function forwardMessage(array $content) {
  137. return $this->endpoint("forwardMessage", $content);
  138. }
  139.  
  140. public function sendPhoto(array $content) {
  141. return $this->endpoint("sendPhoto", $content);
  142. }
  143.  
  144. public function sendAudio(array $content) {
  145. return $this->endpoint("sendAudio", $content);
  146. }
  147.  
  148. public function sendDocument(array $content) {
  149. return $this->endpoint("sendDocument", $content);
  150. }
  151.  
  152. public function sendSticker(array $content) {
  153. return $this->endpoint("sendSticker", $content);
  154. }
  155.  
  156. public function sendVideo(array $content) {
  157. return $this->endpoint("sendVideo", $content);
  158. }
  159.  
  160. public function sendVoice(array $content) {
  161. return $this->endpoint("sendVoice", $content);
  162. }
  163.  
  164. public function sendLocation(array $content) {
  165. return $this->endpoint("sendLocation", $content);
  166. }
  167.  
  168. public function sendVenue(array $content) {
  169. return $this->endpoint("sendVenue", $content);
  170. }
  171.  
  172. public function sendContact(array $content) {
  173. return $this->endpoint("sendContact", $content);
  174. }
  175.  
  176. public function sendChatAction(array $content) {
  177. return $this->endpoint("sendChatAction", $content);
  178. }
  179.  
  180. public function getUserProfilePhotos(array $content) {
  181. return $this->endpoint("getUserProfilePhotos", $content);
  182. }
  183.  
  184. public function getFile($file_id) {
  185. $content = array('file_id' => $file_id);
  186. return $this->endpoint("getFile", $content);
  187. }
  188.  
  189. public function kickChatMember(array $content) {
  190. return $this->endpoint("kickChatMember", $content);
  191. }
  192.  
  193. public function leaveChat(array $content) {
  194. return $this->endpoint("leaveChat", $content);
  195. }
  196.  
  197. public function unbanChatMember(array $content) {
  198. return $this->endpoint("unbanChatMember", $content);
  199. }
  200.  
  201. public function getChat(array $content) {
  202. return $this->endpoint("getChat", $content);
  203. }
  204.  
  205. public function getChatAdministrators(array $content) {
  206. return $this->endpoint("getChatAdministrators", $content);
  207. }
  208.  
  209. public function getChatMembersCount(array $content) {
  210. return $this->endpoint("getChatMembersCount", $content);
  211. }
  212.  
  213. public function getChatMember(array $content) {
  214. return $this->endpoint("getChatMember", $content);
  215. }
  216.  
  217. public function answerInlineQuery(array $content) {
  218. return $this->endpoint("answerInlineQuery", $content);
  219. }
  220.  
  221. public function setGameScore(array $content) {
  222. return $this->endpoint("setGameScore", $content);
  223. }
  224.  
  225. public function answerCallbackQuery(array $content) {
  226. return $this->endpoint("answerCallbackQuery", $content);
  227. }
  228.  
  229. public function editMessageText(array $content) {
  230. return $this->endpoint("editMessageText", $content);
  231. }
  232.  
  233. public function editMessageCaption(array $content) {
  234. return $this->endpoint("editMessageCaption", $content);
  235. }
  236.  
  237. public function editMessageReplyMarkup(array $content) {
  238. return $this->endpoint("editMessageReplyMarkup", $content);
  239. }
  240.  
  241. public function downloadFile($telegram_file_path, $local_file_path) {
  242. $file_url = "https://api.telegram.org/file/bot" . $this->bot_id . "/" . $telegram_file_path;
  243. $in = fopen($file_url, "rb");
  244. $out = fopen($local_file_path, "wb");
  245.  
  246. while ($chunk = fread($in, 8192)) {
  247. fwrite($out, $chunk, 8192);
  248. }
  249. fclose($in);
  250. fclose($out);
  251. }
  252.  
  253. public function setWebhook($url, $certificate = "") {
  254. if ($certificate == "") {
  255. $content = array('url' => $url);
  256. } else {
  257. $content = array('url' => $url, 'certificate' => $certificate);
  258. }
  259. return $this->endpoint("setWebhook", $content);
  260. }
  261.  
  262. public function getData() {
  263. if (empty($this->data)) {
  264. $rawData = file_get_contents("php://input");
  265. return json_decode($rawData, true);
  266. } else {
  267. return $this->data;
  268. }
  269. }
  270.  
  271. public function setData(array $data) {
  272. $this->data = $data;
  273. }
  274.  
  275. public function Text() {
  276. return $this->data["message"] ["text"];
  277. }
  278.  
  279. public function ChatID() {
  280. return $this->data["message"]["chat"]["id"];
  281. }
  282.  
  283. public function MessageID() {
  284. return $this->data["message"]["message_id"];
  285. }
  286.  
  287. public function ReplyToMessageID() {
  288. return $this->data["message"]["reply_to_message"]["message_id"];
  289. }
  290.  
  291. public function ReplyToMessageFromUserID() {
  292. return $this->data["message"]["reply_to_message"]["forward_from"]["id"];
  293. }
  294.  
  295. public function Inline_Query() {
  296. return $this->data["inline_query"];
  297. }
  298.  
  299. public function Callback_Query() {
  300. return $this->data["callback_query"];
  301. }
  302.  
  303. public function Callback_ID() {
  304. return $this->data["callback_query"]["id"];
  305. }
  306.  
  307. public function Callback_Data() {
  308. return $this->data["callback_query"]["data"];
  309. }
  310.  
  311. public function Callback_Message() {
  312. return $this->data["callback_query"]["message"];
  313. }
  314.  
  315. public function Callback_ChatID() {
  316. return $this->data["callback_query"]["message"]["chat"]["id"];
  317. }
  318.  
  319. public function Date() {
  320. return $this->data["message"]["date"];
  321. }
  322.  
  323. public function FirstName() {
  324. return $this->data["message"]["from"]["first_name"];
  325. }
  326.  
  327. public function LastName() {
  328. return $this->data["message"]["from"]["last_name"];
  329. }
  330.  
  331. public function Username() {
  332. return $this->data["message"]["from"]["username"];
  333. }
  334.  
  335. public function Location() {
  336. return $this->data["message"]["location"];
  337. }
  338.  
  339. public function UpdateID() {
  340. return $this->data["update_id"];
  341. }
  342.  
  343. public function UpdateCount() {
  344. return count($this->updates["result"]);
  345. }
  346.  
  347. public function messageFromGroup() {
  348. if ($this->data["message"]["chat"]["type"] == "private") {
  349. return false;
  350. }
  351. return true;
  352. }
  353.  
  354. public function messageFromGroupTitle() {
  355. if ($this->data["message"]["chat"]["type"] != "private") {
  356. return $this->data["message"]["chat"]["title"];
  357. }
  358. return null;
  359. }
  360.  
  361. public function buildKeyBoard(array $options, $onetime = false, $resize = false, $selective = true) {
  362. $replyMarkup = array(
  363. 'keyboard' => $options,
  364. 'one_time_keyboard' => $onetime,
  365. 'resize_keyboard' => $resize,
  366. 'selective' => $selective
  367. );
  368. $encodedMarkup = json_encode($replyMarkup, true);
  369. return $encodedMarkup;
  370. }
  371.  
  372. public function buildInlineKeyBoard(array $options) {
  373. $replyMarkup = array(
  374. 'inline_keyboard' => $options,
  375. );
  376. $encodedMarkup = json_encode($replyMarkup, true);
  377. return $encodedMarkup;
  378. }
  379.  
  380. public function buildInlineKeyboardButton($text, $url = "", $callback_data = "", $switch_inline_query = "", $switch_inline_query_current_chat = "", $callback_game = "") {
  381. $replyMarkup = array(
  382. 'text' => $text
  383. );
  384. if ($url != "") {
  385. $replyMarkup['url'] = $url;
  386. } else if ($callback_data != "") {
  387. $replyMarkup['callback_data'] = $callback_data;
  388. } else if ($switch_inline_query != "") {
  389. $replyMarkup['switch_inline_query'] = $switch_inline_query;
  390. } else if ($switch_inline_query_current_chat != "") {
  391. $replyMarkup['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
  392. } else if ($callback_game != "") {
  393. $replyMarkup['callback_game'] = $callback_game;
  394. }
  395. return $replyMarkup;
  396. }
  397.  
  398. public function buildKeyboardButton($text, $request_contact = false, $request_location = false) {
  399. $replyMarkup = array(
  400. 'text' => $text,
  401. 'request_contact' => $request_contact,
  402. 'request_location' => $request_location
  403. );
  404. if ($url != "") {
  405. $replyMarkup['url'] = $url;
  406. } else if ($callback_data != "") {
  407. $replyMarkup['callback_data'] = $callback_data;
  408. } else if ($switch_inline_query != "") {
  409. $replyMarkup['switch_inline_query'] = $switch_inline_query;
  410. }
  411. return $replyMarkup;
  412. }
  413.  
  414. public function buildKeyBoardHide($selective = true) {
  415. $replyMarkup = array(
  416. 'hide_keyboard' => true,
  417. 'selective' => $selective
  418. );
  419. $encodedMarkup = json_encode($replyMarkup, true);
  420. return $encodedMarkup;
  421. }
  422.  
  423. public function buildForceReply($selective = true) {
  424. $replyMarkup = array(
  425. 'force_reply' => true,
  426. 'selective' => $selective
  427. );
  428. $encodedMarkup = json_encode($replyMarkup, true);
  429. return $encodedMarkup;
  430. }
  431.  
  432. public function getUpdates($offset = 0, $limit = 100, $timeout = 0, $update = true) {
  433. $content = array('offset' => $offset, 'limit' => $limit, 'timeout' => $timeout);
  434. $this->updates = $this->endpoint("getUpdates", $content);
  435. if ($update) {
  436. if(count($this->updates["result"]) >= 1) { //for CLI working.
  437. $last_element_id = $this->updates["result"][count($this->updates["result"]) - 1]["update_id"] + 1;
  438. $content = array('offset' => $last_element_id, 'limit' => "1", 'timeout' => $timeout);
  439. $this->endpoint("getUpdates", $content);
  440. }
  441. }
  442. return $this->updates;
  443. }
  444.  
  445. public function serveUpdate($update) {
  446. $this->data = $this->updates["result"][$update];
  447. }
  448.  
  449. private function sendAPIRequest($url, array $content, $post = true) {
  450. if (isset($content['chat_id'])) {
  451. $url = $url . "?chat_id=" . $content['chat_id'];
  452. unset($content['chat_id']);
  453. }
  454. $ch = curl_init();
  455. curl_setopt($ch, CURLOPT_URL, $url);
  456. curl_setopt($ch, CURLOPT_HEADER, false);
  457. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  458. if ($post) {
  459. curl_setopt($ch, CURLOPT_POST, 1);
  460. curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
  461. }
  462. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  463. $result = curl_exec($ch);
  464. curl_close($ch);
  465. return $result;
  466. }
  467.  
  468. }
  469.  
  470. if (!function_exists('curl_file_create')) {
  471.  
  472. function curl_file_create($filename, $mimetype = '', $postname = '') {
  473. return "@$filename;filename="
  474. . ($postname ? : basename($filename))
  475. . ($mimetype ? ";type=$mimetype" : '');
  476. }
  477.  
  478. }
  479.  
  480. class Mailer {
  481.  
  482. var $site_name = "";
  483. var $from = "";
  484. var $to = "";
  485. var $subject = "";
  486. var $message = "";
  487. var $header = "";
  488. var $error = "";
  489. var $bcc = array ();
  490. var $mail_headers = "";
  491. var $html_mail = 0;
  492. var $charset = 'utf-8';
  493.  
  494. var $smtp_fp = FALSE;
  495. var $smtp_msg = "";
  496. var $smtp_port = "";
  497. var $smtp_host = "localhost";
  498. var $smtp_user = "";
  499. var $smtp_pass = "";
  500. var $smtp_code = "";
  501. var $send_error = FALSE;
  502.  
  503. var $eol = "\n";
  504.  
  505. var $mail_method = 'php';
  506.  
  507. public function prepare($config, $is_html = false) {
  508. $this->mail_method = $config['mail_metod'];
  509.  
  510. $this->from = $config['admin_mail'];
  511. $this->charset = $config['charset'];
  512. $this->site_name = $config['home_title'];
  513.  
  514. $this->smtp_host = $config['smtp_host'];
  515. $this->smtp_port = intval( $config['smtp_port'] );
  516. $this->smtp_user = $config['smtp_user'];
  517. $this->smtp_pass = $config['smtp_pass'];
  518.  
  519. $this->html_mail = $is_html;
  520. }
  521.  
  522. public function compile_headers() {
  523.  
  524. $this->subject = "=?" . $this->charset . "?b?" . base64_encode( $this->subject ) . "?=";
  525. $from = "=?" . $this->charset . "?b?" . base64_encode( $this->site_name ) . "?=";
  526.  
  527. if( $this->html_mail ) {
  528. $this->mail_headers .= "MIME-Version: 1.0" . $this->eol;
  529. $this->mail_headers .= "Content-type: text/html; charset=\"" . $this->charset . "\"" . $this->eol;
  530. } else {
  531. $this->mail_headers .= "MIME-Version: 1.0" . $this->eol;
  532. $this->mail_headers .= "Content-type: text/plain; charset=\"" . $this->charset . "\"" . $this->eol;
  533. }
  534.  
  535. if( $this->mail_method != 'smtp' ) {
  536.  
  537. if( count( $this->bcc ) ) {
  538. $this->mail_headers .= "Bcc: " . implode( ",", $this->bcc ) . $this->eol;
  539. }
  540.  
  541. } else {
  542.  
  543. $this->mail_headers .= "Subject: " . $this->subject . $this->eol;
  544.  
  545. if( $this->to ) {
  546.  
  547. $this->mail_headers .= "To: " . $this->to . $this->eol;
  548. }
  549.  
  550. }
  551.  
  552. $this->mail_headers .= "From: \"" . $from . "\" <" . $this->from . ">" . $this->eol;
  553.  
  554. $this->mail_headers .= "Return-Path: <" . $this->from . ">" . $this->eol;
  555. $this->mail_headers .= "X-Priority: 3" . $this->eol;
  556. $this->mail_headers .= "X-MSMail-Priority: Normal" . $this->eol;
  557. $this->mail_headers .= "X-Mailer: DLE PHP" . $this->eol;
  558.  
  559. }
  560.  
  561. public function send($to, $subject, $message) {
  562. $this->to = preg_replace( "/[ \t]+/", "", $to );
  563. $this->from = preg_replace( "/[ \t]+/", "", $this->from );
  564.  
  565. $this->to = preg_replace( "/,,/", ",", $this->to );
  566. $this->from = preg_replace( "/,,/", ",", $this->from );
  567.  
  568. if( $this->mail_method != 'smtp' )
  569. $this->to = preg_replace( "#\#\[\]'\"\(\):;/\$!£%\^&\*\{\}#", "", $this->to );
  570. else
  571. $this->to = '<' . preg_replace( "#\#\[\]'\"\(\):;/\$!£%\^&\*\{\}#", "", $this->to ) . '>';
  572.  
  573.  
  574. $this->from = preg_replace( "#\#\[\]'\"\(\):;/\$!£%\^&\*\{\}#", "", $this->from );
  575.  
  576. $this->subject = $subject;
  577. $this->message = $message;
  578.  
  579. $this->message = str_replace( "\r", "", $this->message );
  580.  
  581. $this->compile_headers();
  582.  
  583. if( ($this->to) and ($this->from) and ($this->subject) ) {
  584. if( $this->mail_method != 'smtp' ) {
  585. if( ! @mail( $this->to, $this->subject, $this->message, $this->mail_headers ) ) {
  586. $this->smtp_msg = "PHP Mail Error.";
  587. $this->send_error = true;
  588. }
  589.  
  590. } else {
  591. $this->smtp_send();
  592. }
  593.  
  594. }
  595.  
  596. $this->mail_headers = "";
  597.  
  598. }
  599.  
  600. public function smtp_get_line() {
  601. $this->smtp_msg = "";
  602.  
  603. while ( $line = fgets( $this->smtp_fp, 515 ) ) {
  604. $this->smtp_msg .= $line;
  605.  
  606. if( substr( $line, 3, 1 ) == " " ) {
  607. break;
  608. }
  609. }
  610. }
  611.  
  612. public function smtp_send() {
  613. $this->smtp_fp = @fsockopen( $this->smtp_host, intval( $this->smtp_port ), $errno, $errstr, 30 );
  614.  
  615. if( ! $this->smtp_fp ) {
  616. $this->smtp_error( "Could not open a socket to the SMTP server" );
  617. return;
  618. }
  619.  
  620. $this->smtp_get_line();
  621.  
  622. $this->smtp_code = substr( $this->smtp_msg, 0, 3 );
  623.  
  624. if( $this->smtp_code == 220 ) {
  625. $data = $this->smtp_crlf_encode( $this->mail_headers . "\n" . $this->message );
  626.  
  627. $this->smtp_send_cmd( "HELO " . $this->smtp_host );
  628.  
  629. if( $this->smtp_code != 250 ) {
  630. $this->smtp_error( "HELO" );
  631. return;
  632. }
  633.  
  634. if( $this->smtp_user and $this->smtp_pass ) {
  635. $this->smtp_send_cmd( "AUTH LOGIN" );
  636.  
  637. if( $this->smtp_code == 334 ) {
  638. $this->smtp_send_cmd( base64_encode( $this->smtp_user ) );
  639.  
  640. if( $this->smtp_code != 334 ) {
  641. $this->smtp_error( "Username not accepted from the server" );
  642. return;
  643. }
  644.  
  645. $this->smtp_send_cmd( base64_encode( $this->smtp_pass ) );
  646.  
  647. if( $this->smtp_code != 235 ) {
  648. $this->smtp_error( "Password not accepted from the SMTP server" );
  649. return;
  650. }
  651. } else {
  652. $this->smtp_error( "This SMTP server does not support authorisation" );
  653. return;
  654. }
  655. }
  656.  
  657. $this->smtp_send_cmd( "MAIL FROM:<" . $this->from . ">" );
  658.  
  659. if( $this->smtp_code != 250 ) {
  660. $this->smtp_error( "Incorrect FROM address: $this->from" );
  661. return;
  662. }
  663.  
  664. $to_array = array ( $this->to );
  665.  
  666. if( count( $this->bcc ) ) {
  667. foreach ( $this->bcc as $bcc ) {
  668. if( preg_match( "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/", str_replace( " ", "", $bcc ) ) ) {
  669. $to_array[] = "<".$bcc.">";
  670. }
  671. }
  672. }
  673.  
  674. foreach ( $to_array as $to_email ) {
  675. $this->smtp_send_cmd( "RCPT TO:" . $to_email );
  676.  
  677. if( $this->smtp_code != 250 ) {
  678. $this->smtp_error( "Incorrect email address: $to_email" );
  679. return;
  680. break;
  681. }
  682. }
  683.  
  684. $this->smtp_send_cmd( "DATA" );
  685.  
  686. if( $this->smtp_code == 354 ) {
  687. fputs( $this->smtp_fp, $data . "\r\n" );
  688. } else {
  689. $this->smtp_error( "Error on write to SMTP server" );
  690. return;
  691. }
  692.  
  693. $this->smtp_send_cmd( "." );
  694.  
  695. if( $this->smtp_code != 250 ) {
  696. $this->smtp_error();
  697. return;
  698. }
  699.  
  700. $this->smtp_send_cmd( "quit" );
  701.  
  702. if( $this->smtp_code != 221 ) {
  703. $this->smtp_error();
  704. return;
  705. }
  706.  
  707. @fclose( $this->smtp_fp );
  708. } else {
  709. $this->smtp_error( "SMTP service unaviable" );
  710. return;
  711. }
  712. }
  713.  
  714. public function smtp_send_cmd($cmd) {
  715. $this->smtp_msg = "";
  716. $this->smtp_code = "";
  717.  
  718. fputs( $this->smtp_fp, $cmd . "\r\n" );
  719.  
  720. $this->smtp_get_line();
  721.  
  722. $this->smtp_code = substr( $this->smtp_msg, 0, 3 );
  723.  
  724. return $this->smtp_code == "" ? FALSE : TRUE;
  725. }
  726.  
  727. public function smtp_error($err = "") {
  728. $this->smtp_msg = $err;
  729. $this->send_error = true;
  730. return;
  731. }
  732.  
  733. public function smtp_crlf_encode($data) {
  734. $data .= "\n";
  735. $data = str_replace( "\n", "\r\n", str_replace( "\r", "", $data ) );
  736. $data = str_replace( "\n.\r\n", "\n. \r\n", $data );
  737.  
  738. return $data;
  739. }
  740. }
  741.  
  742. new Sender();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement