Hallo...
ich habe mich mal an einer SMTP klasse versucht um eine mail via smtp zu verschicken.
Ich habe jedoch das problem das das script nach 60 secs aufhört... (Maximum execution time of 60 seconds exceeded).
email, host, usernam und passwort wurden natürlich geändert ^^
wäre dankbar wenn mir da einer weiterhelfen kann...
ich habe mich mal an einer SMTP klasse versucht um eine mail via smtp zu verschicken.
Ich habe jedoch das problem das das script nach 60 secs aufhört... (Maximum execution time of 60 seconds exceeded).
PHP:
class messenger extends database
{
/**
* SMTP server port
* @var int
*/
var $_PORT = 25;
/**
* SMTP default server domain
* @var string
*/
var $_domain = "smtp.domain.de";
/**
* SMTP default connection interval
* @var int
*/
var $_tval = 10;
/**
* SMTP username
* @var string
*/
var $_username = "unsername";
/**
* SMTP password
* @var string
*/
var $_password = "password";
/**
* SMTP reply line ending
* @var string
*/
var $CRLF = "\r\n";
/**#@+
* @access private
*/
private $socket; # the socket to the server
private $backtrace = "";
/**#@-*/
public function init()
{
$this->connect();
return true;
}
function connect()
{
$this->socket = fsockopen( $this->_domain, # the host of the server
$this->_PORT, # the port to use
$errno, # error number if any
$errstr, # error message if any
$this->_tval); # give up after ? secs
if(empty($this->socket))
{
$this->add_backtrace(array("# Failed to connect to server.", "# " . $errstr . " (" . $errno . ")"));
return false;
}
$this->add_backtrace("# Connected to " . $this->_domain . $this->CRLF);
# sometimes the SMTP server takes a little longer to respond
# so we will give it a longer timeout for the first read
// Windows still does not have support for this timeout function
if(substr(PHP_OS, 0, 3) != "WIN")
socket_set_timeout($this->socket, $this->_tval, 0);
// das is halt nur zum testen ^^
$this->server_send("HELO " . $this->_domain);
$this->server_send("AUTH LOGIN");
$this->server_send(base64_encode($this->_username));
$this->server_send(base64_encode($this->_password), true);
$this->server_send("MAIL FROM: email@domain.de");
$this->server_send("RCPT TO: email@domain.de");
$this->server_send("DATA");
$hdr = "From: email@domain.de\r\n";
$hdr .= "To: email@domain.de\r\n";
$hdr .= "Reply-To: email@domain.de\r\n";
$hdr .= "Subject: Testmail\r\n";
$this->server_send($hdr);
$this->server_send("Das ist nur eine Testnachricht.");
$this->server_send($this->CRLF . ".");
// end test
return true;
}
/**
* Send command to smtp server
*/
function server_send($command, $private_info = false)
{
fputs($this->socket, $command . $this->CRLF);
(!$private_info) ? $this->add_backtrace("# $command" . $this->CRLF) : $this->add_backtrace("# Omitting sensitive information" . $this->CRLF);
$this->parse();
}
/*
* $@$ Internal functions
*/
private function connected()
{
if(!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->socket);
if($sock_status["eof"]) {
# hmm this is an odd situation... the socket is
# valid but we aren't connected anymore
//$this->Close();
return false;
}
return true; # everything looks good
}
return false;
}
private function parse()
{
$msg = fgets($this->socket, 1024);
$this->add_backtrace("#Server: " . $msg);
return $msg;
}
private function add_backtrace($msg)
{
if (is_array($msg))
while ($ma = each($msg)) { $this->backtrace .= $ma['value'] . $this->CRLF; }
else
$this->backtrace .= $msg;
}
function close()
{
if ($this->socket)
{
$this->server_send("QUIT");
$this->parse();
fclose($this->socket);
return true;
}
return false;
}
// destructor
function __destruct()
{
$this->close();
$sql = "INSERT INTO `" . LOG_TABLE . "` (
`action`, `time`, `rate`
) VALUES (
'" . $this->backtrace . "',
UNIX_TIMESTAMP(),
6);";
parent::sql_Execute($sql);
}
}
email, host, usernam und passwort wurden natürlich geändert ^^
wäre dankbar wenn mir da einer weiterhelfen kann...