$SMTP->host_name= "mail.xiaocui.com";
$smtp->localhost= "localhost";
$from = "webmaster@xiaocui.com";
$to = "root@xiaocui.com";
if ($smtp->sendmessage (
$from,
Array
$to
),
Array
"From: $from",
"To: $to",
"Subject:testing Manuel Lemos ' SMTP class"
),
"Hello $to, Nnit is just to we know that your SMTP class is working just FINE.NNBYE.N"))
echo "message sent to $to OK.N";
Else
echo "Cound not send" $to. Nerror: ". $smtp->error." N
?>
smtp.php
Class Smtp_class
{
var $host _name= "";
var $host _port=25;
var $localhost = "";
var $timeout = 0;
var $error = "";
var $debug = 1;
var $esmtp = 1;
var $esmtp _host= "";
var $esmtp _extensions=array ();
var $maximum _piped_recipients=100;
/* Private variables-do not ACCESS * *
var $state = "Disconnected";
var $connection = 0;
var $pending _recipients=0;
/* Private methods-do not call * *
Function Outputdebug ($message)
{
Echo $message, "
n ";
}
Function Getline ()
{
for ($line = "";;)
{
if (feof ($this->connection))
{
$this->error= "reached the end of the stream while reading from socket";
return (0);
}
if (($data =fgets ($this->connection,100)) ==false)
{
$this->error= "It is not possible to read line from socket";
return (0);
}
$line. = $data;
$length =strlen ($line);
if ($length >=2
&& substr ($line, $length -2,2) = = "RN")
{
$line =substr ($line, 0, $length-2);
if ($this->debug)
$this->outputdebug ("< $line");
return ($line);
}
}
}
Function Putline ($line)
{
if ($this->debug)
$this->outputdebug ("> $line");
if (!fputs ($this->connection, "$linern"))
{
$this->error= "It is not possible to write line to socket";
return (0);
}
return (1);
}
Function PutData ($data)
{
if (strlen ($data))
{
if ($this->debug)
$this->outputdebug ("> $data");
if (!fputs ($this->connection, $data))
{
$this->error= "It is not possible to write data to socket";
return (0);
}
}
return (1);
}
Function verifyresultlines ($code, $responses = "")
{
if (GetType ($responses)!= "Array")
$responses =array ();
Unset ($match _code);
Function SendData ($data)
{
if (strcmp ($this->state, "Sendingdata"))
{
$this->error= "Connection is isn't in the sending data state";
return (0);
}
$this->error= "";
Return ($this->putdata (& $data));
}
Function Endsendingdata ()
{
if (strcmp ($this->state, "Sendingdata"))
{
$this->error= "Connection is isn't in the sending data state";
return (0);
}
$this->error= "";
if (! $this->putline ("RN.")
|| $this->verifyresultlines ("<=0")
return (0);
$this->state= "Connected";
return (1);
}
Function resetconnection ()
{
Switch ($this->state)
{
Case "Connected":
return (1);
Case "Sendingdata":
$this->error= "Can not reset the connection while sending data";
return (0);
Case "Disconnected":
$this->error= "Can not reset the connection before it is established";
return (0);
}
$this->error= "";
if (! $this->putline ("RSET")
|| $this->verifyresultlines ("<=0")
return (0);
$this->state= "Connected";
return (1);
}
Function Disconnect ($quit =1)
{
if (!strcmp ($this->state, "Disconnected"))
{
$this->error= "It is not previously established a SMTP connection";
return (0);
}
$this->error= "";
if (!strcmp ($this->state, "Connected")
&& $quit
&& (! $this->putline ("QUIT")
|| $this->verifyresultlines ("221") <=0))
return (0);
Fclose ($this->connection);
$this->connection=0;
$this->state= "Disconnected";
return (1);
}
Function SendMessage ($sender, $recipients, $headers, $body)
{
if (($success = $this->connect ()))
{
if (($success = $this->mailfrom ($sender)))
{
for ($recipient =0; $recipient {
if (!) ( $success = $this->setrecipient ($recipients [$recipient]))
Break
}
if ($success
&& ($success = $this->startdata ()))
{
for ($header _data= "", $header =0 $header $header _data.= $headers [$header]. " RN ";
if ($success = $this->senddata ($header _data.) RN))
{
$this->preparedata ($body,& $body _data);
$success = $this->senddata ($body _data);
}
if ($success)
$success = $this->endsendingdata ();
}
}
$disconnect _success= $this->disconnect ($success);
if ($success)
$success = $disconnect _success;
}
return ($success);
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.