• 自己写的一个php发送邮件的类(smtp协议)


    调用方法:<?php 
     $smtp = new Smtp; 
      
     $smtp->smtp('smtp.qq.com');           //邮件发送服务器 
     $smtp->pors(25);                      //邮件服务器端口 
     $smtp->login( '369758482@qq.com');     //邮件服务器登录用户 
     $smtp->pass(2013);             //邮件服务器登录密码 
     $smtp->mails( '1140714215@qq.com');    //邮件接收人 
     $smtp->from( '369758482@qq.com');      //邮件发送人 
     $smtp->come( 'baiyi1983000@163.com');  //接收邮件回复地址 
     $smtp->title('这是一封邮件测试地址邮件');  //邮件主题 
     $smtp->body('这是一封邮件测试内容邮件');   //邮件内容 
     echo $smtp->send();                   //发送邮件并输出发送状态 
    ?> 
    也可以这样调用: 
     $smtp = new Smtp; 
      
     echo $smtp->smtp('smtp.qq.com')->pors(25)->login( '369758482@qq.com')->pass(13979797582)->mails('1140714215@qq.com')->from('369758482@qq.com')->come('baiyi1983000@163.com')->title('这是一封邮件测试地址邮件')->body('这是一封邮件测试内容邮件')->send();        

     1 <?php
     2 /*
     3 SMTP发送邮件类
     4 作者:伤心的歌
     5 QQ:369758482
     6 Email:369758482@qq.com
     7 */
     8 class Smtp{
     9     private $Smtp      = 'smtp.qq.com'; //邮件服务器
    10     private $PORS      = 25;            //邮件服务器端口
    11     private $LoginMail = '';            //邮件登陆用户账户
    12     private $LoginPass = '';            //邮件登陆用户密码
    13     private $MailTo    = '';            //接受邮件用户
    14     private $MailFrom  = '';            //邮件发送人
    15     private $MailCome  = '';            //接受回复邮件账户
    16     private $Title     = '测试邮件主题';  //邮件主题
    17     private $Body      = '测试邮件内容';  //邮件主体内容
    18     private $Mesg      = '邮件发送成功';  //邮件发送结果
    19     
    20     
    21     public function smtp( $Smtp = '' ){ $this -> Smtp = $Smtp; return $this; }
    22     public function pors( $pors = 25 ){ $this -> PORS = $pors; return $this; }
    23     public function login( $login = '' ) { $this -> LoginMail = $login; return $this; }
    24     public function pass( $pass = '' ){ $this -> LoginPass = $pass; return $this; }
    25     public function mails( $mail = '' ) { $this -> MailTo = $mail; return $this; }
    26     public function from( $form = '' ) { $this -> MailFrom = $form; return $this; }
    27     public function come( $come = '' ) { $this -> MailCome = $come; return $this; }
    28     public function title( $title = '' ) { $this -> Title = $title; return $this; }
    29     public function body( $body = '' ) { $this -> Body = $body; return $this; }
    30     
    31     
    32     public function send(){
    33           $fp     = @fsockopen( $this->Smtp, $this->PORS);
    34           @set_socket_blocking($fp, true);
    35           $Server =  @fgets($fp, 512);
    36           $this->Mesg = !preg_match('/^220/i', $Server) ? '邮件服务器连接失败' : $this->Mesg;
    37           
    38           @fputs($fp, 'HELO phpsetmail' . "\r\n");
    39           $Server = @fgets($fp, 2000);
    40           $this->Mesg = !preg_match('/^250/i', $Server) ? '与服务器会话失败' : $this->Mesg;
    41           
    42           @fputs($fp, 'AUTH LOGIN' . "\r\n");
    43           $Server = @fgets($fp, 2000);
    44           $this->Mesg = !preg_match('/^334/i', $Server) ? '请求与服务器进行用户验证失败' : $this->Mesg;
    45           
    46           @fputs($fp, base64_encode( $this->LoginMail ) . "\r\n");
    47           $Server = @fgets($fp, 2000);
    48           $this->Mesg = !preg_match('/^334/i', $Server) ? '用户验证失败' : $this->Mesg;
    49           
    50           @fputs($fp, base64_encode( $this->LoginPass ) . "\r\n");
    51           $Server = @fgets($fp, 2000);
    52           $this->Mesg = !preg_match('/^235/i', $Server) ? '用户验证失败' : $this->Mesg;
    53           
    54           @fputs($fp, 'MAIL FROM:' . $this->LoginMail . "\r\n");
    55           $Server = @fgets($fp, 2000);
    56           $this->Mesg = !preg_match('/^250/i', $Server) ? '发送用户验证失败' : $this->Mesg;
    57           
    58           @fputs($fp, 'RCPT TO:' . $this->MailTo . "\r\n");
    59           $Server = @fgets($fp, 2000);
    60           $this->Mesg = !preg_match('/^250/i', $Server) ? '接受用户名验证失败' : $this->Mesg;
    61           
    62           @fputs($fp, 'DATA' . "\r\n");
    63           $Server = @fgets($fp, 2000);
    64           $this->Mesg = !preg_match('/^354/i', $Server) ? '请求与服务器发送邮件数据失败' : $this->Mesg;
    65           
    66           @fputs($fp, 'From:' . $this->MailCome ."\r\n");
    67           @fputs($fp, 'Subject:' . $this->Title . "\r\n");
    68           @fputs($fp, 'To:' . $this->MailTo . "\r\n");
    69           @fputs($fp, "\r\n");
    70           @fputs($fp, $this->Body . "\r\n");
    71           @fputs($fp, '.' . "\r\n");
    72           
    73           $Server = @fgets($fp, 2000);
    74           $this->Mesg = !preg_match('/^250/i', $Server) ? '邮件发送失败' : $this->Mesg;
    75           
    76           @@fputs($fp, 'QUIT' . "\r\n");
    77           @fclose($fp);
    78          return $this->Mesg;
    79     }
    80     
    81 }
  • 相关阅读:
    (数据集)Quality of Web Service (QWS) Datasets
    [扫盲] Salesforce.com: 业界云计算(Cloud Computing)的主要倡导者之一
    Major conference/journal for Web Service [updating]
    ICWS 2009 Accepted Research Paper List (63篇)
    [论文笔记]Web服务集成的策略规划 (CIMS 2008)
    [论文笔记]Global and Local QoS Guarantee in Web Service Selection (BPM 2005)
    [论文笔记](东北大学)基于组合服务执行信息的服务选取方法研究(计算机学报, 2008)
    WWW2009相关论文
    [文章笔记]Web Service Discovery and Client Goals(Computers, 2009)
    [论文笔记](东北大学)支持组合服务选取的QoS模型及优化求解(计算机学报06)
  • 原文地址:https://www.cnblogs.com/ymj0906/p/2992654.html
Copyright © 2020-2023  润新知