<?  
class smtp_sender
{  
    var $host; 
    var $port; 
    var $user; 
    var $pass; 
    var $debug = false; 
    var $conn;  
    var $result_str;
    var $in; 
    var $from; 
    var $to; 
    var $subject; 
    var $body; 
    var $socket;
    
    function smtp_sender($debug=false)
    {
           $this->smtp_ori('mail.99419.com','25','[email protected]','web',$debug);
  
    }
    function smtp_ori($host,$port,$user,$pass,$debug=false)  
    {  
        $this->host   = $host;   
        $this->port   = $port;   
        $this->user   = base64_encode($user);   
        $this->pass   = base64_encode($pass);   
        $this->debug  = $debug;   
        $this->socket = fsockopen($this->host,$this->port, $errno, $errstr, 30);
        
        if (!$this->socket) 
         {
           die("error:$errstr ($errno)<br />\n");
         } 
     }   
    function debug_show($str)   
    {   
         if($this->debug==true)   
         {   
            echo $str."<br>\r\n";   
         }   
    }   
    function send($from,$to,$subject,$body,$mailtype="html",$fromname="Hostelcn.com")   
    {   
         if($from == "" || $to == "")   
         {   
            exit("you must enter email address");   
         }            if($subject == "") $sebject = "no subject";   
         if($body    == "") $body    = "no content";   
         $body = str_replace("\n", "\r\n", $body);
         $body = str_replace("\r\r", "\r", $body);         
         $this->from     =  $from;   
         $this->to      =  $to;   
         $this->subject  =  $subject;   
         $this->body     =  $body;            $All           = "From: $fromname<".$this->from.">\r\n";   
         $All          .= "To: ".$this->to."\r\n";   
         $All          .= "Subject: ".$this->subject."\r\n";   
         $All                   .= "MIME-Version: 1.0\r\n";
     if(strtolower($mailtype)=="html")  
         $All                  .="Content-Type: text/html;charset=\"gb2312\"\r\n";
         $All                   .= "Date: ".date("r")."\r\n";
         $All                   .= "X-Mailer: Microsoft Outlook Express 5.50.4522.1200\r\n";
     list($msec, $sec) = explode(" ", microtime());
         $All                   .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$from.">\r\n\r\n";
         $All          .= $this->body;   
        
         $this->in       =  "EHLO HELO\r\n";   
         $this->sendcommand();   
         $this->in       =  "AUTH LOGIN\r\n";   
         $this->sendcommand();   
         $this->in       =  $this->user."\r\n";   
         $this->sendcommand();   
         $this->in       =  $this->pass."\r\n";   
         $this->sendcommand();   
         $this->in       =  "MAIL FROM:".$this->from."\r\n";   
         $this->sendcommand();   
         $this->in       =  "RCPT TO:".$this->to."\r\n";   
         $this->sendcommand();   
         $this->in       =  "DATA\r\n";   
         $this->sendcommand();   
         $this->in       =  $All."\r\n.\r\n";;            
         $this->sendcommand();   
         $this->in       =  "QUIT\r\n";   
         $this->sendcommand();   
     
    }   
    function sendcommand()   
    {   
        fwrite($this->socket, $this->in);   
        $this->debug_show("Command:".$this->in);   
        $this->result_str = "Response".fread ($this->socket, 1024)."";   
        $this->debug_show($this->result_str);   
    }   
}     $host="mail.99419.com"; 
    $port="25"; 
    $user="[email protected]"; 
    $pass="web"; 
    $debug = false; 
    $result_str="发送成功";
    $from="[email protected]"; 
    $to="[email protected]"; 
    $subject="这是我的"; 
    $body="这是我的"; 
    $socket;
smtp_sender($host,$port,$user,$pass,$debug,$result_str,$from,$to,$subject,$body);
?>