phpmailer实现发送注册验证邮件

微信群消息监控系统实战:从零搭建Python自动化监控平台 本文详细介绍了如何从零搭建Python微信群消息监控系统,实现自动化监控和记录群消息。通过wxauto库模拟人工操作微信,结合MySQL数据库存储和智能去重策略,系统能高效处理大量消息并支持关键词监控。文章还分享了性能优化、安全合规等实战经验,帮助开发者快速构建高效稳定的监控平台。 阅读详情

今天下午才弄好

步骤如下:

1、http://sourceforge.net/projects/phpmailer/ 下载phpmail的类文件

2、解压,将class.phpmailer.php和class.smtp.php 两个文件放到项目里

3、开始写代码啦!目标实现,邮件从admin@163.com 发送到admin@qq.com


if (!defined( "PT_PATH" )) {
   define( "PT_PATH", dirname(__FILE__)."/");
}
require_once 'phpmailer/class.phpmailer.php';
include_once(PT_PATH.'phpmailer/class.smtp.php');
function send_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){   
        $mail = new PHPMailer();   
        $mail->IsSMTP();                  // send via SMTP   
        $mail->Host = "smtp.163.com";   // SMTP servers  
        $mail->PORT = 994;    
        $mail->SMTPAuth = true;           // turn on SMTP authentication   
        $mail->Username = "admin";     // SMTP username  注意:普通邮件认证不需要加 @域名   
        $mail->Password = "123456"; // SMTP password   
        $mail->From = "admin@163.com";      // 发件人邮箱   
        $mail->FromName =  "发件人";  // 发件人   
        $mail->CharSet = "UTF-8";   // 这里指定字符集!   
        $mail->Encoding = "base64";   
        $mail->AddAddress($sendto_email,"111111");  // 收件人邮箱和姓名   
        $mail->IsHTML(true);  // send as HTML   
        $mail->Subject = $subject;   
        $mail->Body = "<html><head><meta http-equiv=\"Content-Language\" content=\"zh-cn\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head> <body> I love php。   </body>  </html>  ";                                                                         
        $mail->AltBody ="text/html";   
        if(!$mail->Send())   
        {   
            echo "邮件发送有误 <p>";   
            echo "邮件错误信息: " . $mail->ErrorInfo;   
            exit;   
        }   
        else {   
            echo "$user_name 邮件发送成功!<br />";   
        }   
    }   
    // 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)   
   send_mail("admin@qq.com", "欢迎使用phpmailer!", "NULL", "yourdomain.com", "admin"); 
    

附上class.smtp.php的代码,网上一开始找了一个居然是错的。。。。

<?php
/*~ class.smtp.php
.---------------------------------------------------------------------------.
|  Software: PHPMailer - PHP email class                                    |
|   Version: 2.0.0 rc1                                                      |
|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
|      Info: http://phpmailer.sourceforge.net                               |
|   Support: http://sourceforge.net/projects/phpmailer/                     |
| ------------------------------------------------------------------------- |
|    Author: Andy Prevost (project admininistrator)                         |
|    Author: Brent R. Matzelle (original founder)                           |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
| Copyright (c) 2001-2003, Brent R. Matzelle                                |
| ------------------------------------------------------------------------- |
|   License: Distributed under the Lesser General Public License (LGPL)     |
|            http://www.gnu.org/copyleft/lesser.html                        |
| This program is distributed in the hope that it will be useful - WITHOUT  |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
| FITNESS FOR A PARTICULAR PURPOSE.                                         |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com):                |
| - Web Hosting on highly optimized fast and secure servers                 |
| - Technology Consulting                                                   |
| - Oursourcing (highly qualified programmers and graphic designers)        |
'---------------------------------------------------------------------------'
 
/* SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
 * commands except TURN which will always return a not implemented
 * error. SMTP also provides some utility methods for sending mail
 * to an SMTP server.
 */
 
class SMTP
{
  /* SMTP server port
   * @var int
   */
  var $SMTP_PORT = 25;
 
  /* SMTP reply line ending
   * @var string
   */
  var $CRLF = "\r\n";
 
  /* Sets whether debugging is turned on
   * @var bool
   */
  var $do_debug;       # the level of debug to perform
 
  /*
   * @access private
   */
  var $smtp_conn;      # the socket to the server
 var $error;          # error if any on the last call
 var $helo_rply;      # the reply the server sent to us for HELO
 
  /* Initialize the class so that the data is in a known state.
   * @access public
   * @return void
   */
  function SMTP() {
    $this->smtp_conn = 0;
    $this->error = null;
    $this->helo_rply = null;
 
    $this->do_debug = 0;
  }
 
  /* CONNECTION FUNCTIONS */
 
  /* Connect to the server specified on the port specified.
   * If the port is not specified use the default SMTP_PORT.
   * If tval is specified then a connection will try and be
   * established with the server for that number of seconds.
   * If tval is not specified the default is 30 seconds to
   * try on the connection.
   *
   * SMTP CODE SUCCESS: 220
   * SMTP CODE FAILURE: 421
   * @access public
   * @return bool
   */
  function Connect($host,$port=0,$tval=30) {
    # set the error val to null so there is no confusion
   $this->error = null;
 
    # make sure we are __not__ connected
   if($this->connected()) {
      # ok we are connected! what should we do?
     # for now we will just give an error saying we
     # are already connected
     $this->error = array("error" => "Already connected to a server");
      return false;
    }
 
    if(empty($port)) {
      $port = $this->SMTP_PORT;
    }
 
    #connect to the smtp server
   $this->smtp_conn = fsockopen($host,    # the host of the server
                                $port,    # the port to use
                                $errno,   # error number if any
                                $errstr,  # error message if any
                                $tval);   # give up after ? secs
   # verify we connected properly
   if(empty($this->smtp_conn)) {
      $this->error = array("error" => "Failed to connect to server",
                           "errno" => $errno,
                           "errstr" => $errstr);
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": $errstr ($errno)" . $this->CRLF;
      }
      return false;
    }
 
    # sometimes the SMTP server takes a little longer to respond
   # so we will give it a longer timeout for the first read
   // Windows still does not have support for this timeout function
    if(substr(PHP_OS, 0, 3) != "WIN")
     socket_set_timeout($this->smtp_conn, $tval, 0);
 
    # get any announcement stuff
   $announce = $this->get_lines();
 
    # set the timeout  of any socket functions at 1/10 of a second
   //if(function_exists("socket_set_timeout"))
    //   socket_set_timeout($this->smtp_conn, 0, 100000);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
    }
 
    return true;
  }
 
  /* Performs SMTP authentication.  Must be run after running the
   * Hello() method.  Returns true if successfully authenticated.
   * @access public
   * @return bool
   */
  function Authenticate($username, $password) {
    // Start authentication
    fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($code != 334) {
      $this->error =
        array("error" => "AUTH not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    // Send encoded username
    fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($code != 334) {
      $this->error =
        array("error" => "Username not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    // Send encoded password
    fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($code != 235) {
      $this->error =
        array("error" => "Password not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    return true;
  }
 
  /* Returns true if connected to a server otherwise false
   * @access private
   * @return bool
   */
  function Connected() {
    if(!empty($this->smtp_conn)) {
      $sock_status = socket_get_status($this->smtp_conn);
      if($sock_status["eof"]) {
        # hmm this is an odd situation... the socket is
       # valid but we are not connected anymore
       if($this->do_debug >= 1) {
            echo "SMTP -> NOTICE:" . $this->CRLF .
                 "EOF caught while checking if connected";
        }
        $this->Close();
        return false;
      }
      return true; # everything looks good
   }
    return false;
  }
 
  /* Closes the socket and cleans up the state of the class.
   * It is not considered good to use this function without
   * first trying to use QUIT.
   * @access public
   * @return void
   */
  function Close() {
    $this->error = null; # so there is no confusion
   $this->helo_rply = null;
    if(!empty($this->smtp_conn)) {
      # close the connection and cleanup
     fclose($this->smtp_conn);
      $this->smtp_conn = 0;
    }
  }
 
 
  /* SMTP COMMANDS */
 
  /* Issues a data command and sends the msg_data to the server
   * finializing the mail transaction. $msg_data is the message
   * that is to be send with the headers. Each header needs to be
   * on a single line followed by a <CRLF> with the message headers
   * and the message body being seperated by and additional <CRLF>.
   *
   * Implements rfc 821: DATA <CRLF>
   *
   * SMTP CODE INTERMEDIATE: 354
   *     [data]
   *     <CRLF>.<CRLF>
   *     SMTP CODE SUCCESS: 250
   *     SMTP CODE FAILURE: 552,554,451,452
   * SMTP CODE FAILURE: 451,554
   * SMTP CODE ERROR  : 500,501,503,421
   * @access public
   * @return bool
   */
  function Data($msg_data) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Data() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"DATA" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 354) {
      $this->error =
        array("error" => "DATA command not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    # the server is ready to accept data!
   # according to rfc 821 we should not send more than 1000
   # including the CRLF
   # characters on a single line so we will break the data up
   # into lines by \r and/or \n then if needed we will break
   # each of those into smaller lines to fit within the limit.
   # in addition we will be looking for lines that start with
   # a period '.' and append and additional period '.' to that
   # line. NOTE: this does not count towards are limit.
 
    # normalize the line breaks so we know the explode works
   $msg_data = str_replace("\r\n","\n",$msg_data);
    $msg_data = str_replace("\r","\n",$msg_data);
    $lines = explode("\n",$msg_data);
 
    # we need to find a good way to determine is headers are
   # in the msg_data or if it is a straight msg body
   # currently I am assuming rfc 822 definitions of msg headers
   # and if the first field of the first line (':' sperated)
   # does not contain a space then it _should_ be a header
   # and we can process all lines before a blank "" line as
   # headers.
   $field = substr($lines[0],0,strpos($lines[0],":"));
    $in_headers = false;
    if(!empty($field) && !strstr($field," ")) {
      $in_headers = true;
    }
 
    $max_line_length = 998; # used below; set here for ease in change
 
    while(list(,$line) = @each($lines)) {
      $lines_out = null;
      if($line == "" && $in_headers) {
        $in_headers = false;
      }
      # ok we need to break this line up into several
     # smaller lines
     while(strlen($line) > $max_line_length) {
        $pos = strrpos(substr($line,0,$max_line_length)," ");
 
        # Patch to fix DOS attack
       if(!$pos) {
          $pos = $max_line_length - 1;
        }
 
        $lines_out[] = substr($line,0,$pos);
        $line = substr($line,$pos + 1);
        # if we are processing headers we need to
       # add a LWSP-char to the front of the new line
       # rfc 822 on long msg headers
       if($in_headers) {
          $line = "\t" . $line;
        }
      }
      $lines_out[] = $line;
 
      # now send the lines to the server
     while(list(,$line_out) = @each($lines_out)) {
        if(strlen($line_out) > 0)
        {
          if(substr($line_out, 0, 1) == ".") {
            $line_out = "." . $line_out;
          }
        }
        fputs($this->smtp_conn,$line_out . $this->CRLF);
      }
    }
 
    # ok all the message data has been sent so lets get this
   # over with aleady
   fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "DATA not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Expand takes the name and asks the server to list all the
   * people who are members of the _list_. Expand will return
   * back and array of the result or false if an error occurs.
   * Each value in the array returned has the format of:
   *     [ <full-name> <sp> ] <path>
   * The definition of <path> is defined in rfc 821
   *
   * Implements rfc 821: EXPN <SP> <string> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE FAILURE: 550
   * SMTP CODE ERROR  : 500,501,502,504,421
   * @access public
   * @return string array
   */
  function Expand($name) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
            "error" => "Called Expand() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "EXPN not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    # parse the reply and place in our array to return to user
   $entries = explode($this->CRLF,$rply);
    while(list(,$l) = @each($entries)) {
      $list[] = substr($l,4);
    }
 
    return $list;
  }
 
  /* Sends the HELO command to the smtp server.
   * This makes sure that we and the server are in
   * the same known state.
   *
   * Implements from rfc 821: HELO <SP> <domain> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE ERROR  : 500, 501, 504, 421
   * @access public
   * @return bool
   */
  function Hello($host="") {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
            "error" => "Called Hello() without being connected");
      return false;
    }
 
    # if a hostname for the HELO was not specified determine
   # a suitable one to send
   if(empty($host)) {
      # we need to determine some sort of appopiate default
     # to send to the server
     $host = "localhost";
    }
 
    // Send extended hello first (RFC 2821)
    if(!$this->SendHello("EHLO", $host))
    {
      if(!$this->SendHello("HELO", $host))
          return false;
    }
 
    return true;
  }
 
  /* Sends a HELO/EHLO command.
   * @access private
   * @return bool
   */
  function SendHello($hello, $host) {
    fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => $hello . " not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    $this->helo_rply = $rply;
 
    return true;
  }
 
  /* Gets help information on the keyword specified. If the keyword
   * is not specified then returns generic help, ussually contianing
   * A list of keywords that help is available on. This function
   * returns the results back to the user. It is up to the user to
   * handle the returned data. If an error occurs then false is
   * returned with $this->error set appropiately.
   *
   * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
   *
   * SMTP CODE SUCCESS: 211,214
   * SMTP CODE ERROR  : 500,501,502,504,421
   * @access public
   * @return string
   */
  function Help($keyword="") {
    $this->error = null; # to avoid confusion
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Help() without being connected");
      return false;
    }
 
    $extra = "";
    if(!empty($keyword)) {
      $extra = " " . $keyword;
    }
 
    fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 211 && $code != 214) {
      $this->error =
        array("error" => "HELP not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    return $rply;
  }
 
  /* Starts a mail transaction from the email address specified in
   * $from. Returns true if successful or false otherwise. If True
   * the mail transaction is started and then one or more Recipient
   * commands may be called followed by a Data command.
   *
   * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE SUCCESS: 552,451,452
   * SMTP CODE SUCCESS: 500,501,421
   * @access public
   * @return bool
   */
  function Mail($from) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Mail() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "MAIL not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Sends the command NOOP to the SMTP server.
   *
   * Implements from rfc 821: NOOP <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE ERROR  : 500, 421
   * @access public
   * @return bool
   */
  function Noop() {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Noop() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"NOOP" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "NOOP not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Sends the quit command to the server and then closes the socket
   * if there is no error or the $close_on_error argument is true.
   *
   * Implements from rfc 821: QUIT <CRLF>
   *
   * SMTP CODE SUCCESS: 221
   * SMTP CODE ERROR  : 500
   * @access public
   * @return bool
   */
  function Quit($close_on_error=true) {
    $this->error = null; # so there is no confusion
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Quit() without being connected");
      return false;
    }
 
    # send the quit command to the server
   fputs($this->smtp_conn,"quit" . $this->CRLF);
 
    # get any good-bye messages
   $byemsg = $this->get_lines();
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
    }
 
    $rval = true;
    $e = null;
 
    $code = substr($byemsg,0,3);
    if($code != 221) {
      # use e as a tmp var cause Close will overwrite $this->error
     $e = array("error" => "SMTP server rejected quit command",
                 "smtp_code" => $code,
                 "smtp_rply" => substr($byemsg,4));
      $rval = false;
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $e["error"] . ": " .
                 $byemsg . $this->CRLF;
      }
    }
 
    if(empty($e) || $close_on_error) {
      $this->Close();
    }
 
    return $rval;
  }
 
  /* Sends the command RCPT to the SMTP server with the TO: argument of $to.
   * Returns true if the recipient was accepted false if it was rejected.
   *
   * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
   *
   * SMTP CODE SUCCESS: 250,251
   * SMTP CODE FAILURE: 550,551,552,553,450,451,452
   * SMTP CODE ERROR  : 500,501,503,421
   * @access public
   * @return bool
   */
  function Recipient($to) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Recipient() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250 && $code != 251) {
      $this->error =
        array("error" => "RCPT not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Sends the RSET command to abort and transaction that is
   * currently in progress. Returns true if successful false
   * otherwise.
   *
   * Implements rfc 821: RSET <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE ERROR  : 500,501,504,421
   * @access public
   * @return bool
   */
  function Reset() {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Reset() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"RSET" . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "RSET failed",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
 
    return true;
  }
 
  /* Starts a mail transaction from the email address specified in
   * $from. Returns true if successful or false otherwise. If True
   * the mail transaction is started and then one or more Recipient
   * commands may be called followed by a Data command. This command
   * will send the message to the users terminal if they are logged
   * in.
   *
   * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE SUCCESS: 552,451,452
   * SMTP CODE SUCCESS: 500,501,502,421
   * @access public
   * @return bool
   */
  function Send($from) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Send() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "SEND not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Starts a mail transaction from the email address specified in
   * $from. Returns true if successful or false otherwise. If True
   * the mail transaction is started and then one or more Recipient
   * commands may be called followed by a Data command. This command
   * will send the message to the users terminal if they are logged
   * in and send them an email.
   *
   * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE SUCCESS: 552,451,452
   * SMTP CODE SUCCESS: 500,501,502,421
   * @access public
   * @return bool
   */
  function SendAndMail($from) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
          "error" => "Called SendAndMail() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "SAML not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* Starts a mail transaction from the email address specified in
   * $from. Returns true if successful or false otherwise. If True
   * the mail transaction is started and then one or more Recipient
   * commands may be called followed by a Data command. This command
   * will send the message to the users terminal if they are logged
   * in or mail it to them if they are not.
   *
   * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE SUCCESS: 552,451,452
   * SMTP CODE SUCCESS: 500,501,502,421
   * @access public
   * @return bool
   */
  function SendOrMail($from) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
          "error" => "Called SendOrMail() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250) {
      $this->error =
        array("error" => "SOML not accepted from server",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return true;
  }
 
  /* This is an optional command for SMTP that this class does not
   * support. This method is here to make the RFC821 Definition
   * complete for this class and __may__ be implimented in the future
   *
   * Implements from rfc 821: TURN <CRLF>
   *
   * SMTP CODE SUCCESS: 250
   * SMTP CODE FAILURE: 502
   * SMTP CODE ERROR  : 500, 503
   * @access public
   * @return bool
   */
  function Turn() {
    $this->error = array("error" => "This method, TURN, of the SMTP ".
                                    "is not implemented");
    if($this->do_debug >= 1) {
      echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
    }
    return false;
  }
 
  /* Verifies that the name is recognized by the server.
   * Returns false if the name could not be verified otherwise
   * the response from the server is returned.
   *
   * Implements rfc 821: VRFY <SP> <string> <CRLF>
   *
   * SMTP CODE SUCCESS: 250,251
   * SMTP CODE FAILURE: 550,551,553
   * SMTP CODE ERROR  : 500,501,502,421
   * @access public
   * @return int
   */
  function Verify($name) {
    $this->error = null; # so no confusion is caused
 
    if(!$this->connected()) {
      $this->error = array(
              "error" => "Called Verify() without being connected");
      return false;
    }
 
    fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
 
    $rply = $this->get_lines();
    $code = substr($rply,0,3);
 
    if($this->do_debug >= 2) {
      echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
    }
 
    if($code != 250 && $code != 251) {
      $this->error =
        array("error" => "VRFY failed on name '$name'",
              "smtp_code" => $code,
              "smtp_msg" => substr($rply,4));
      if($this->do_debug >= 1) {
        echo "SMTP -> ERROR: " . $this->error["error"] .
                 ": " . $rply . $this->CRLF;
      }
      return false;
    }
    return $rply;
  }
 
  /* INTERNAL FUNCTIONS */
 
  /* Read in as many lines as possible
   * either before eof or socket timeout occurs on the operation.
   * With SMTP we can tell if we have more lines to read if the
   * 4th character is '-' symbol. If it is a space then we don't
   * need to read anything else.
   * @access private
   * @return string
   */
  function get_lines() {
    $data = "";
    while($str = @fgets($this->smtp_conn,515)) {
      if($this->do_debug >= 4) {
        echo "SMTP -> get_lines(): \$data was \"$data\"" .
                 $this->CRLF;
        echo "SMTP -> get_lines(): \$str is \"$str\"" .
                 $this->CRLF;
      }
      $data .= $str;
      if($this->do_debug >= 4) {
        echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
      }
      # if the 4th character is a space then we are done reading
     # so just break the loop
     if(substr($str,3,1) == " ") { break; }
    }
    return $data;
  }
 
}
 
 
 ?>


GameFramework专栏目录 本专栏是专门介绍GameFramework框架的,持续更新中,如有疑问可留言,24小时内回复。 阅读详情

相关推荐

OneNet平台MQTT连接避坑指南:C语言Token计算实战(附完整代码)

本文详细解析了OneNet平台MQTT连接中的Token计算机制,提供了C语言实现的完整代码和实战指南。通过HMAC算法和Base64编码,开发者可以高效生成安全凭证,避免常见连接问题,适用于物联网设备开发。

weixin_29193359的博客 468

PHPMailer - PHP email transport class

PHPMailer - PHP email transport class

hsyyff的博客 166

STM32CubeMx+stm32f407+FreeRTOS+LAN8720实现LWIP以太网UDP TCP数据收发功能

单片机实现LWIP的调试

qq_40600203的博客 3082

php发送邮件

新建文件 smtp.clss.php  里面代码不用修改! 代码如下: class smtp_class{      var $Priority   = 3;  var $CharSet   = "iso-8859-1";  var $ContentType  = "text/plain";  var $Encoding   = "8bit";  var $FromEmail   = "root

在行进路上的博客 405

FreeSWITCH实战:5分钟搞定阿里云SDM(MRCP-SERVER)语音机器人搭建(含Docker部署技巧)

本文详细介绍了如何利用FreeSWITCH与阿里云SDM(MRCP-SERVER)快速搭建高可用语音机器人,包括Docker部署技巧、系统调优及高可用架构设计。通过实战案例和优化建议,帮助开发者5分钟内完成部署,提升语音交互系统的性能和稳定性。

stone的博客 510

从入门到精通:Cursor使用全攻略

Cursor是一款基于VSCode深度定制的AI编程工具,由Anysphere公司开发。它将AI技术与代码开发深度融合,能够理解自然语言指令并生成高质量代码,支持代码补全、跨文件上下文理解等功能。本文详细介绍了Cursor的安装设置、界面导航、基本操作和Composer模式等核心功能,并提供了高效提示词写作技巧和实际应用案例(如浏览器插件开发、复杂表单组件构建等)。文章还总结了使用注意事项和常见问题解决方案,展望了AI编程工具的发展前景。Cursor通过智能代码生成和项目理解能力,显著提升了开发效率,适合各

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 6466

使用phpmailer发送邮件(以QQ邮箱为例)

mail->AddReplyTo("回复地址","from");$mail->AddAddress("收件人","to");$mail->Username="发件人";$mail->From = "发件人";$mail->Body = "你的邮件的内容";

m0_62089210的博客 793

Algorithm:【算法进阶之路】之算法面试刷题集合—数据结构的简介、最强学习路线(逻辑结构【数组-链表-栈和队列/树-图-哈希】、物理结构【元素/关系】、数据运算【十大排序/四大查找-图三大搜索-

​ Algorithm:【算法进阶之路】之算法面试刷题集合—数据结构的简介、最强学习路线(逻辑结构【数组-链表-栈和队列/树-图-哈希】、物理结构【元素/关系】、数据运算【十大排序/四大查找-图三大搜索-树三大遍历】、高级算法【枚举/回溯/递归/分治/动规/贪心】)、问题为导向的十大类刷题算法总结之详细攻略 目录 相关文章 数据结构思维导图 基本术语 一、数据结构的概述 二、数据的逻辑结构 三、数据的物理结构 四、数据的运算

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 6860

web hosting上opencart发送邮件问题解决方法

按照网上的方法,一直去尝试解决 opencart 2.0 出现的 “Error: EHLO not accepted from server” 问题,但是一直都没有成功。后来翻墙google在一个英文网站上找到了答案: “This topic is just for the purpose of sharing information on one of the problem spots in

xinghun_4的专栏 6815

Microsemi Libero使用技巧11——CoreUARTAPB RX管脚分配时不显示

调用串口IP核CoreUARTAPB,并例化到顶层设计,发现UART_RX管脚在进行管脚分配时没有显示出来,最后发现是CoreAPB3总线IP核配置不对导致,改为如下配置后正常。

whik1194的博客 764

【YOLO11改进 - C3k2融合】C3k2融合AKConv(可改变核卷积)二次创新:任意数量的参数和任意采样形状的即插即用的卷积

【YOLO11改进 - C3k2融合】C3k2融合AKConv(可改变核卷积)二次创新:任意数量的参数和任意采样形状的即插即用的卷积

专注于图像领域,主要研究内容包括计算机视觉和深度学习,特别是在图像分类、目标检测和图像生成等方面有深入的研究和实践经验。 408

MySQL报The server quit without updating PID file的6种解决方法

第一种、权限问题 执行 chown -R mysql:mysql /mysql安装目录 chmod -R 775 /mysql安装目录下的data目录 第二种、到data目录下查看是否有ib_logfile前缀的文件备份下 删除后重启 第三种、进程问题 通过命令查询进程号然后杀死 ps -ef|grep mysqld kill -9 进程号 第四种、硬盘满了,通过df . 查询硬盘使用情况,如果确定占用了100%就要清理硬盘中无用的数据,释放一定量的空间给MYSQL了 第五种、重装后的m.

wcy1900353090的博客 1万+

最新Python爬虫实战(入门爬虫篇)——案例7:电影网站电影数据采集(详细爬虫思路截图+抓包动图演示+完整爬虫代码+详细注释)

本次案例通过Python爬虫技术,成功实现了对某电影网站Top250多页电影详细信息的批量爬取与Excel保存。代码采用模块化设计,包含分页请求构造、XPath+正则提取结构化信息、Excel数据持久化保存等完整流程。通过配置User-Agent等请求头信息,有效模拟浏览器行为以绕过豆瓣基础反爬策略。整个爬虫逻辑遵循"分页遍历 → 请求页面 → 解析HTML → 提取电影信息 → 保存到Excel"的标准流程,与主流静态网站爬取范式高度一致。

努力让自己发光,对的人才能迎着光而来 11万+

PHP 实现 注册等的邮箱验证 (二)—— 使用 PHPMailer 发送邮件

PHPMailer 是一个很好的发送邮件的类 , 最近使用了它。因为还没有搭起来邮件服务器,先使用他的 SMTP 发送邮件,测试之前邮箱验证的链接是否有效。 谷歌了一下,发现关于这方面的资料还挺多,我参考了网上的资料 ,自己写了一个 函数function smtp_send_m

杨帆的博客 5280

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

php 发送邮箱验证怎么做,PHP 实现 注册等的邮箱验证 (二)—— 使用 PHPMailer 发送邮件...

PHPMailer 是一个很好的发送邮件的类 , 最近使用了它。因为还没有搭起来邮件服务器,先使用他的 SMTP 发送邮件,测试之前邮箱验证的链接是否有效。谷歌了一下,发现关于这方面的资料还挺多,我参考了网上的资料 ,自己写了一个 函数function smtp_send_mail($destAddress ,$subject , $content ,$fromName) ;有不完善的地方,不能添...

weixin_42228776的博客 345

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

ThinkPHP3.2使用PHPMailer发送邮件

首先下载PHPMailer,直接在百度搜下,然后下载就好了。 接着注册一个新浪邮箱,用作发件人邮箱。qq和163邮箱都不稳定,有时邮件发不出去。 解压下载的文件(如果是压缩包),得到PHPMailer文件夹,文件夹下有以下文件: 紧接着把这个文件夹放到ThinkPhp中的Library中的Vendor下,具体路径为:项目文件夹\ThinkPHP\Library\Vendor\

liujan511536的专栏 6956

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

PHP使用PHPMailer发送邮件

背景知识: 邮件的使用场景一般有很多,例如用户注册,消息通知等等,本案例以用户注册发送验证码为场景 PHPMailer是一个PHP相关的邮件类,使用它可以很轻松的发送邮件 1.使用composer安装PHPMailer,PHPMailer的github主页:PHPMailer下载。例如可以在桌面创建一个测试目录phpmail,按住shift+鼠标右键,选择在此处打开命令窗口,输入如下命令安装...

wx145的博客 4677

php, TP5 中实现邮件发送功能

在TP5中实现邮件发送功能 邮件验证码找回密码,账户注册 客户信息推送 使用composer,安装PHPmailer,用PHPmailer实现邮件发送功能 1.如果你的电脑没有安装composer则先要安装,安装步骤及下载地址 TP5项目中下载,安装composer工具 2.下载安装完成之后打开composer,在Thinkphp项目目录的extend文件下运行安装PHPmailer co...

Trailbreaker 796

PHPMailer实战案例:用户注册验证邮件

你是否曾经遇到过这样的场景:用户注册后需要发送验证邮件,但使用PHP原生`mail()`函数时经常遇到邮件被标记为垃圾邮件、发送失败、或者格式混乱的问题?传统的邮件发送方式不仅功能有限,还存在安全隐患和兼容性问题。 PHPMailer作为PHP领域最受欢迎的邮件发送库,已经被WordPress、Drupal、Joomla!等众多知名项目采用。本文将为你详细解析如何使用PHPMailer构建专业级...

gitblog_00862的博客 885

PHP 发送验证邮件 并用GET方法处理验证信息

今天研究了用PHP发送验证邮件的流程,基本流程是这样的:用户填写完注册信息并提交,后台验证完通过后会向用户邮箱发送一条系统邮件,邮件内容里有一个链接地址,用户进入注册邮箱接收邮件并点击链接即完成用户验证。思路还是很清晰的,而且大部分用户注册网站都是这么处理的。这里有个细节,一般出于GET方式安全考虑,验证码采用密文,通过GET方式获得的密文经解码后再与数据库内的明文验证码比较。有些朋友可能考虑数据

u011324672的专栏 1363

php邮箱验证怎么实现,php实现邮箱验证

php实现邮箱验证2020-09-30 19:49:37php实现邮箱验证的方法:首先下载phpMailer;然后解压到项目根目录下;接着需要一台邮件服务器;最后在“config.php”中配置邮箱相关的信息并创建用于发送邮件的公用方法即可。推荐:《PHP视频教程》一、Introduction需求是用户在注册时填写email,注册后,需要到邮箱验证后才能登陆。二、实现验证流程,注册成功后,为用户生...

weixin_39815286的博客 1242

php实现邮箱验证

一、Introduction 需求是用户在注册时填写email,注册后,需要到邮箱验证后才能登陆。 二、实现 验证流程,注册成功后,为用户生成一个验证码;将验证码以连接方式发到用户邮箱;用户点击连接将验证码发回网站;网站验证这个验证码是否是为这个用户生成的验证码;帐号需要在24小时内验证,否则帐号失效。 1.        准备工作 需要添加phpMailer类来发邮件。下载phpMai...

HelloWorld 1万+

php 邮箱绑定,php实现邮箱验证

php实现邮箱验证的方法:首先下载phpMailer;然后解压到项目根目录下;接着需要一台邮件服务器;最后在“config.php”中配置邮箱相关的信息并创建用于发送邮件的公用方法即可。一、Introduction需求是用户在注册时填写email,注册后,需要到邮箱验证后才能登陆。二、实现验证流程,注册成功后,为用户生成一个验证码;将验证码以连接方式发到用户邮箱;用户点击连接将验证码发回网站;网站...

weixin_35275671的博客 729

Thinkphp5.1实现发送邮箱验证码

这里使用的是 phpmailer/phpmailer 这个类 第一步加载类 composer installphpmailer/phpmailer 第二步编写公共方法 /** * 邮箱验证码 * @param string $to 发送到邮箱 * @param string $name 当前邮箱服务器 * @return string $subject 发送标题 * @return string $body 发送内容 * @return string $attachment...

http://xueshuai.top 1539

php yeah 发送邮箱,ThnikPHP 3.2 整合PHPmailer 发送SMTP邮件

网站使用TP3.2开发,需要使用SMTP邮件注册验证功能,网上研究很多内容,自己尝试并且整理如下 postbrid : There I am , in the world more exciting! www.ptbird.cn1. 下载PHPmailer并copy到目录2. 进行config配置3. 函数sendmail实现主要功能4. 重要错误指出一、下载PHPmailer并copy到网站目录...

weixin_39654465的博客 361

php注册页面 邮件回复,PHP发送邮件确认验证注册功能示例【修改别人邮件类】...

本文实例讲述了PHP发送邮件确认验证注册功能。分享给大家供大家参考,具体如下:类库:require "class.phpmailer.php";require "class.smtp.php";class PHP_Mailer{protected $mail;public function __construct(){$mail = new PHPMailer;$mail->SMTPDebu...

weixin_35426345的博客 251
上一篇: 阿里云配置php+mysql
下一篇: uploadify+jcrop实现头像上传裁剪功能
程序媛kathy
博客等级 码龄11年 1粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值