<?php
class smtpconnection
{
private $host;
public function __construct($host)
{
$this->host=$host;
}
public function sendmail($mail)
{
$connection=@fsockopen($this->host,25);
if ($connection==false)
{
return false;
}
stream_set_timeout($connection,0,50000);
fgets($connection);
fwrite($connection,'EHLO '.$_SERVER['SERVER_NAME']."\r\n");
$response=fgets($connection);
if (substr($response,0,1)!=2)
{
fclose($connection);
return false;
}
while (fgets($connection)!=false)
{
}
$startpos=strpos($mail,"From: ")+6;
$endpos=strpos($mail,"\r\n",$startpos);
$from=substr($mail,$startpos,$endpos-$startpos);
$startpos=strpos($mail,"To: ")+4;
$endpos=strpos($mail,"\r\n",$startpos);
$to=substr($mail,$startpos,$endpos-$startpos);
$size=strlen($mail);
fwrite($connection,'MAIL FROM:<'.$from.'> SIZE='.$size."\r\n");
$response=fgets($connection);
if (substr($response,0,1)!=2)
{
fclose($connection);
return false;
}
fwrite($connection,'RCPT TO:<'.$to.">\r\n");
$response=fgets($connection);
if (substr($response,0,1)!=2)
{
fclose($connection);
return false;
}
fwrite($connection,"DATA\r\n");
$response=fgets($connection);
if (substr($response,0,1)!=3)
{
fclose($connection);
return false;
}
fwrite($connection,$mail."\r\n.\r\n");
$response=fgets($connection);
if (substr($response,0,1)!=2)
{
fclose($connection);
return false;
}
fwrite($connection,"QUIT\r\n");
fgets($connection);
fclose($connection);
return true;
}
}
?>