免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 901 | 回复: 0
打印 上一主题 下一主题

一个老的smtp类 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-16 14:06 |只看该作者 |倒序浏览
www.phpx.com
* Modifications:
*        2002-11-16   initial modified by goodyork
*
*/
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('smtp服务器地址','smtp端口','用户名','密码',$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)
\n");
         }
     }   
    function debug_show($str)   
    {   
         if($this->debug==true)   
         {   
            echo $str."
\r\n";   
         }   
    }   
    function send($from,$to,$subject,$body,$mailtype="html",$fromname="默认显示的发件人名字")   
    {   
         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: $fromnamefrom.">\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: \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);   
    }   
}
//following is a sample  ,注意事项:发送html格式邮件时,message需要做nl2br
/*
    $mail_title="喜悦国际村密码提醒邮件";
    $message .= "\t喜悦国际村密码提醒邮件!\r\n\r\n";
    $message .= "\t您的用户名是:".$UserName."\r\n\r\n";
  $message .= "\t您的密码是:".$Password."\r\n\r\n";   
    $message .= "\t喜悦国际村  PHP因你而精彩\r\n\r\n";
  $smtpsender=new smtp_sender(true);
  $smtpsender->send("发件人email","收件人email",$mail_title,nl2br($message),"html");  
*/
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/13004/showart_68250.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP