Potřebuju ze svý stránky odeslat mail, to není složitý když není požadováno SMTP ověření. Na netu sem našel nějakou třídu,ale hlásí to chybu:
<b>Fatal error</b>: Using $this when not in object context in <b>C:\PHPDevPack\www\Denik_001\class.smtp.inc</b> on line <b>77</b><br />
tady je kousek zdrojáku třídy (class.smtp.inc):
define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
define('SMTP_STATUS_CONNECTED', 2, TRUE);
class smtp{
private $connection;
private $recipients;
private $headers;
private $timeout;
private $errors;
private $status;
private $body;
private $from;
private $host;
private $port;
private $helo;
private $auth;
private $user;
private $pass;
public function __construct($params = array()){
if(!defined('CRLF'))
define('CRLF', "\r\n", TRUE);
$this->timeout = 5;
$this->status = SMTP_STATUS_NOT_CONNECTED;
$this->host = 'localhost';
$this->port = 25;
$this->helo = 'localhost';
$this->auth = FALSE;
$this->user = '';
$this->pass = '';
$this->errors = array();
foreach($params as $key => $value){
$this->$key = $value;
}
}
public function connect($params = array()){
//$obj = new smtp($params);
77: if(!isset($this->status)){
$obj = new smtp($params);
if($obj->connect()){
$obj->status = SMTP_STATUS_CONNECTED;
}
return $obj;
}else{
$this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
socket_set_timeout($this->connection, 0, 250000);
$greeting = $this->get_data();
if(is_resource($this->connection)){
return $this->auth ? $this->ehlo() : $this->helo();
}else{
$this->errors[] = 'Failed to connect to server: '.$errstr;
return FALSE;
}
}
}
.
.
.
.
další funkce
}
tady kousek příkladu:
někde na začátku je:
include('class.smtp.inc');
if(is_object($smtp = smtp::connect($params)) AND $smtp->send($send_params)){
echo 'Email sent successfully!'."\r\n\r\n";
// Any recipients that failed (relaying denied for example) will be logged in the errors variable.
print_r($smtp->errors);
}else{
echo 'Error sending mail'."\r\n\r\n";
// The reason for failure should be in the errors variable
print_r($smtp->errors);
}
Poradí někdo? Uvítám i jiný nápad jak odeslat mail.