首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>PHP专区>编程技巧>PHP利用Jmai组件实现邮件的发送代码
PHP利用Jmai组件实现邮件的发送代码
来源: 发布时间:2008-07-03 发布人: 浏览: 人次   字体: [ ]  

代码三如下:
<?php
class smtp
{
  /* Public Variables */
  var $smtp_port;
  var $time_out;
  var $host_name;
  var $log_file;
  var $relay_host;
  var $debug;
  var $auth;
  var $user;
  var $pass;
  /* Private Variables */
  var $sock;
  /* Constractor */
  function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
  {
    $this->debug = FALSE;
    $this->smtp_port = $smtp_port;
    $this->relay_host = $relay_host;
    $this->time_out = 30; //is used in fsockopen()
    #
    $this->auth = $auth;//auth
    $this->user = $user;
    $this->pass = $pass;
    #
    $this->host_name = "localhost"; //is used in HELO command
    $this->log_file = "";
    $this->sock = FALSE;
  }
  /* Main Function */
  function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
  {
    $mail_from = $this->get_address($this->strip_comment($from));
    $body = ereg_replace("(^|( ))(.)", "1.3", $body);
    $header = "MIME-Version:1.0 ";
    if($mailtype=="HTML"){
      $header .= "Content-Type:text/html ";
    }
    $header .= "To: ".$to." ";
    if ($cc != "") {
      $header .= "Cc: ".$cc." ";
    }
    $header .= "From: $from<".$from."> ";
    $header .= "Subject: ".$subject." ";
    $header .= $additional_headers;
    $header .= "Date: ".date("r")." ";
    $header .= "X-Mailer:By Redhat (PHP/".phpversion().") ";
    list($msec, $sec) = explode(" ", microtime());
    $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from."> ";
    $TO = explode(",", $this->strip_comment($to));
    if ($cc != "") {
      $TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
    }
    if ($bcc != "") {
      $TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
    }
    $sent = TRUE;
    foreach ($TO as $rcpt_to) {
      $rcpt_to = $this->get_address($rcpt_to);
      if (!$this->smtp_sockopen($rcpt_to)) {
        $this->log_write("Error: Cannot send email to ".$rcpt_to." ");
        $sent = FALSE;
        continue;
      }
      if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
        $this->log_write("E-mail has been sent to <".$rcpt_to."> ");
      } else {
        $this->log_write("Error: Cannot send email to <".$rcpt_to."> ");
        $sent = FALSE;
      }
      fclose($this->sock);
      $this->log_write("Disconnected from remote host ");
    }
    return $sent;
  }
/* Private Functions */
  function smtp_send($helo, $from, $to, $header, $body = "")
  {
    if (!$this->smtp_putcmd("HELO", $helo)) {
      return $this->smtp_error("sending HELO command");
    }
    #auth
    if($this->auth){
      if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
        return $this->smtp_error("sending HELO command");
      }
      if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
        return $this->smtp_error("sending HELO command");
      }
    }
    #
    if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
      return $this->smtp_error("sending MAIL FROM command");
    }
    if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
      return $this->smtp_error("sending RCPT TO command");
    }
    if (!$this->smtp_putcmd("DATA")) {
      return $this->smtp_error("sending DATA command");
    }
    if (!$this->smtp_message($header, $body)) {
      return $this->smtp_error("sending message");
    }
    if (!$this->smtp_eom()) {
      return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
    }
    if (!$this->smtp_putcmd("QUIT")) {
      return $this->smtp_error("sending QUIT command");
    }
    return TRUE;
  }

共3页: 上一页 [1] 2 [3] 下一页
相 关 文 章   发布商链接
·实例讲解php实现中文水印的代码
·PHP是如何设置COOKIE的保留时间为浏...
·PHP读取站点的链接函数代码实例
·实例讲解PHP原生代码生成RSS文档
·利用PHP制作简单的内容采集器
·用PHP来构建自定义搜索引擎
·用PHP程序直接调用文本文件内容实例
·如何用PHP对文本文件加密并限制特定...
·PHP实现Mysql远程同步代码
·PHP程序开发利用PDFLib扩展模块动态...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·实例讲解PHP原生代码生成RSS...
·PHP读取站点的链接函数代码实
·PHP是如何设置COOKIE的保留时
·实例讲解php实现中文水印的代
·PHP程序开发利用PDFLib扩展模
·PHP实现Mysql远程同步代码
·如何用PHP对文本文件加密并限
·用PHP程序直接调用文本文件内
·用PHP来构建自定义搜索引擎
·利用PHP制作简单的内容采集器
热 门 文 章
·PHP实现Mysql远程同步代码
·PHP程序开发利用PDFLib扩展模...
·用PHP来构建自定义搜索引擎
·如何用PHP对文本文件加密并限...
·利用PHP制作简单的内容采集器
·实例讲解php实现中文水印的代...
·用PHP程序直接调用文本文件内...
·实例讲解PHP原生代码生成RSS...
·PHP读取站点的链接函数代码实...
·PHP是如何设置COOKIE的保留时...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .