Im in the process of writing a mailing list for members. I have about 1000 people on the list and need to email quickly, im told mail() is too slow to use for this kind of task so I am using the following smtp class, the problem is it only sends one email for some reason. I thought I would be able to connect to my smtp server and then send them and then close the connection, can I do this or do i have to connect, send, exit - connect, send, exit etc.......
<?php
class smtp_client
{
var $connection;
var $server;
function smtp_client() {
$this->server="localhost";
$this->connection = fsockopen($this->server, 25);
fputs($this->connection,"HELO point_purchasing\r\n");
}
function email($to_mail, $to_name, $subject, $body) {
if ($this->connection <= 0) return 0;
fputs($this->connection,"MAIL FROM:support@mysite.com\r\n");
fputs($this->connection, "RCPT TO:$to_mail\r\n");
fputs($this->connection, "DATA\r\n");
fputs($this->connection,"Subject: $subject\r\n");
fputs($this->connection,"To: $to_name\r\n");
// fputs($this->connection, "$header\r\n");
fputs($this->connection,"\r\n");
fputs($this->connection,"$body \r\n");
fputs($this->connection,".\r\n");
return 1;
}
function send() {
if ($this->connection) {
fputs($this->connection, "QUIT\r\n");
fclose($this->connection);
$this->connection=0;
}
}
function close() { $this->send(); }
}
?>