Problemer med en mail class login
Goddag derude jeg faldt over denne clas i nogle spørgsmål om det sammen men jeg har lidt problemer med den:<?php
class smtp_client {
var $connection;
var $server;
var $elog_fp;
var $log_file='./smtp_client.log';
var $do_log=true;
// default constructor
function smtp_client($server='customer-smtp.one.com') { //din udbyders smtp server
if (!$server) $this->server="localhost";
else $this->server=$server;
$this->connection = fsockopen($this->server, 25);
if ($this->connection <= 0) return 0;
$this->elog(fgets($this->connection, 1024));
$this->elog("HELO xyz\r\n", 1);
fputs($this->connection,"HELO xyz\r\n");
$this->elog(fgets($this->connection, 1024));
}
function email($from_mail, $to_mail, $to_name, $header, $subject, $body) {
if ($this->connection <= 0) return 0;
$this->elog("MAIL FROM:$from_mail", 1);
fputs($this->connection,"MAIL FROM:$from_mail\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("RCPT TO:$to_mail", 1);
fputs($this->connection, "RCPT TO:$to_mail\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("DATA", 1);
fputs($this->connection, "DATA\r\n");
$this->elog(fgets($this->connection, 1024));
$this->elog("Subject: $subject", 1);
$this->elog("To: $to_name", 1);
fputs($this->connection,"Subject: $subject\r\n");
fputs($this->connection,"To: $to_name\r\n");
if ($header) {
$this->elog($header, 1);
fputs($this->connection, "$header\r\n");
}
$this->elog("", 1);
$this->elog($body, 1);
$this->elog(".", 1);
fputs($this->connection,"\r\n");
fputs($this->connection,"$body \r\n");
fputs($this->connection,".\r\n");
$this->elog(fgets($this->connection, 1024));
return 1;
}
function send() {
if ($this->connection) {
fputs($this->connection, "QUIT\r\n");
fclose($this->connection);
$this->connection=0;
}
}
function close() { $this->send(); }
function elog($text, $mode=0) {
if (!$this->do_log) return;
// open file
if (!$this->elog_fp) {
if (!($this->elog_fp=fopen($this->log_file, 'a'))) return;
fwrite($this->elog_fp, "\n-------------------------------------------\n");
fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "\n");
fwrite($this->elog_fp, "-------------------------------------------\n");
}
// write to log
if (!$mode) fwrite($this->elog_fp, " $text\n");
else fwrite($this->elog_fp, "$text\n");
}
}
mysql_connect("localhost", "***" ,"***") or die (mysql_error());
mysql_select_db("***") or die (mysql_error());
$res = mysql_query("select til, navn from test") or die (mysql_error());
$from = "test@kalendersystem.dk"; //din egen mail :-)
$header = "Content-type: text/plain; charset=ISO-8859-1";
$subject = "Test af fsockopen()";
$body = "Dette er en test";
$smtp = new smtp_client;
$smtp -> smtp_client();
while (list($til, $navn) = mysql_fetch_row($res)) {
$smtp->email("$from", "$til", "$navn", "$header", "$subject", "$body");
}
$smtp->send();
mysql_close();
?>
I min database har jeg laver 2 felter så den kører 2 gange det ser også ud til at virke, men den sender ingen mails...
-------------------------------------------
Sent 2007-01-06 17:51:36
-------------------------------------------
220 csmtp1.b-one.net ESMTP Postfix (Debian/GNU)
HELO xyz
250 csmtp1.b-one.net
220 csmtp1.b-one.net ESMTP Postfix (Debian/GNU)
HELO xyz
250 csmtp1.b-one.net
MAIL FROM:test@kalendersystem.dk
250 Ok
RCPT TO:talker3333@hotmail.com
553 <test@kalendersystem.dk>: Sender address rejected: not logged in
DATA
554 Error: no valid recipients
Subject: Test af fsockopen()
To: Ronnie1
Content-type: text/plain; charset=ISO-8859-1
Dette er en test
.
221 Error: I can break rules, too. Goodbye.
MAIL FROM:test@kalendersystem.dk
RCPT TO:talker3333@hotmail.com
DATA
Subject: Test af fsockopen()
To: Ronnie2
Content-type: text/plain; charset=ISO-8859-1
Dette er en test
.
Den snakker om at jeg ikke er logget ind? Det er som om den ikke mener jeg har indtastet en rigtig "fra mail" hvis jeg forstår den korrekt...
