<?php class MailSmtp{ var $host; var $port; var $loginUsr; var $pass; /** * SMTP server port * @var int */ var $defport = 25; /** * Timeout socket * @var int */ var $deftimeout = 10; /**#@+ * @access private */ var $timeout; var $error; var $socket; var $debug; var $tmp; /**#@-*/ function MailSmtp($host, $port = '', $login = '', $pass = '', $timeout = ''){ $this -> host = $host; $this -> loginUsr = $login; $this -> pass = $pass; $this -> port = $this -> defport; } else { $this -> port = $port; } $this -> timeout = $this -> deftimeout; } else { $this -> timeout = $timeout; } $this -> debug = 1; $this -> error = null; $this -> socket = 0; } function Connect(){ $errno =''; $errstr =''; if ($this -> Connected()){ $error = $this -> Error(5); } if ($this -> debug >= 1){ } return false; } } $smtp['ehlo'] = "EHLO rn"; $smtp['helo'] = "HELO $this -> host rn"; $this -> cmd($smtp['ehlo']); $this -> Login(); } else { $this -> cmd($smtp['helo']); } return true; } function Connected(){ if ($sock['eof']){ $this -> close(); return false; } return true; } return false; } function Login($type = 'LOGIN'){ $login = $this -> loginUsr; $login2 = $this -> loginUsr; $pass = $this -> pass; $smtp['auth'] = "AUTH LOGIN rn"; $smtp['authplain'] = "AUTH PLAIN rn"; if ($type == 'LOGIN'){ $this -> cmd($smtp['auth']); } elseif ($type == 'PLAIN'){ //Jescze nie ma :) } } function sendmail($from, $to, $subject, $message){ //Nadawca listu $this->cmd("MAIL FROM:<".$from.">rn"); //Odbiorca listu $this->cmd("RCPT TO:<".$to.">rn"); //Wysyłanie data $this->cmd("DATArn"); #$smtp['auth'] = "AUTH LOGIN rn"; #$this -> cmd($smtp['auth']); /* temat wiadomosci */ $this->cmd("Subject: ".$subject."rn"); /* kodowanie */ $this->cmd("Content-type: text/html; charset=iso-8859-2rn"); /* naglowki */ $this->cmd("From: ".$from."rn"); $this->cmd("Reply-To: ".$from."rn"); $this->cmd("Return-Path: ".$from."rnrn"); /* tresc wiadomosci */ $this->cmd($message."rn"); $this->cmd(".rn"); // koniec wiadomosci } function cmd($msg){ $get = $this -> get(); if ($this -> debug >= 1){ } if ($this -> tmp >= 211 and $this -> tmp <= 400){ return true; } elseif ($this -> tmp > 400){ return false; } } else { if ($this -> debug >= 1){ } return false; } } function get(){ $data = ''; { $data .= $str.'</br>'; break 1; } else { $data .= $str.'</br>'; } } return $data; } function Disconnect(){ $this -> cmd("QUIT"); $this -> socket = 0; } function close(){ $this -> error = null; $this -> socket = 0; } } function Error($num, $msg='') { switch ($num){ case 5: return 'Już jesteś połonczony'; case 6: return 'Nie można sie połonczyć'; case 7: return 'Nie można wysłać do serwera'; case 211: return 'HELP: '.$msg; case 214: return 'Komunikat pomocy dla użytkownika'.$msg; case 220: return 'Informacje o gotowości usługi.'; case 221: return 'Zamykanie połonczenia.'; case 250: return 'Powodzenie żądanej operacji.'; case 251: return 'Użytkownik nie odnaleziony, przekazywanie na adres '.$msg; case 345: return; case 421: return; case 450: return; case 451: return; case 452: return; case 500: return 'Polecenie nie zostało rozpoznane lub ma niepoprawną składnię.'; case 501: return 'Błąd w składni parametrów lub opcji polecenia'; case 502: return 'Polecenie nie obsługiwane'; case 503: return 'Niewłaściwa kolejność przesyłanych poleceń.'; case 504: return 'Parametr polecenia nie jest obsługiwany.'; case 550: return; case 551: return; case 552: return; case 553: return; case 554: return; } } } $mail = new MailSmtp('mail.praca-pl.com',25,'hands@praca-pl.com','*****'); $mail -> Connect(); $mail -> sendmail('hands@praca-pl.com','outlawreg@gmail.com','To jest temat wiadomośći','A tu jest treść wiadomości'); $mail -> Disconnect(); ?>
Cały ten skrypt wykonuje się na serwerze api_smtp.php