14. oktober 2002 - 13:56
#2
jeg bruger :
while (list($navn, $email) = mysql_fetch_row($result)) {
$smtp->email($from, $email, $navn, $header, $subject, $body);
}
14. oktober 2002 - 14:04
#4
class smtp_client {
var $connection;
var $server;
var $elog_fp;
var $log_file='/home/domæne/web/log/log.log';
var $do_log=true;
// default constructor
function smtp_client($server='') { //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");
}
}
$result = sql1("select navn, email from kundekartotek where email !='' ORDER BY navn") or die (mysql_error());
$antalmodtres=mysql_num_rows($result);
$antalmodtagere=$antalmodtres;
$from = "nyhedsmail@domæne.dk";
$from_navn = "Nyhedsmail domæne.dk";
$header = "Content-type: text/html; charset=iso-8859-1";
$body = "$mail_bruger";
$smtp = new smtp_client;
$smtp -> smtp_client();
while (list($navn, $email) = mysql_fetch_row($result)) {
$smtp->email($from, $email, $navn, $header, $subject, $body);
}
$smtp->send();
$dato = date("dmy-His",time());
$old_file = "/home/domæne/web/log/log.log";
$new_file = "/home/domæne/web/log/NY_$dato.log";
rename ($old_file, $new_file);
$besked = addslashes($besked);
$subj = addslashes($subject);
$afsender = "$from_navn <$from>";
$datotid = time();
sql1("insert into newsmail_log (id,tid,emne,besked,afsender,hvem,antalmodtagere) values ('','$datotid','$subj','$besked','$afsender','$hvem','$antalmodtagere')") or die (mysql_error());
echo "Done. Beskeden er sendt!<br>Antal modtagere : $antalmodtagere";
$a = !$a;
}