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

  function smtp_sockopen($address)
  {
    if ($this->relay_host == "") {
      return $this->smtp_sockopen_mx($address);
    } else {
      return $this->smtp_sockopen_relay();
    }
  }
  function smtp_sockopen_relay()
  {
    $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port." ");
    $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
    if (!($this->sock && $this->smtp_ok())) {
      $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host." ");
      $this->log_write("Error: ".$errstr." (".$errno.") ");
      return FALSE;
    }
    $this->log_write("Connected to relay host ".$this->relay_host." ");
    return TRUE;
  }
  function smtp_sockopen_mx($address)
  {
    $domain = ereg_replace("^.+@([^@]+)$", "1", $address);
    if (!@getmxrr($domain, $MXHOSTS)) {
      $this->log_write("Error: Cannot resolve MX "".$domain."" ");
      return FALSE;
    }
    foreach ($MXHOSTS as $host) {
      $this->log_write("Trying to ".$host.":".$this->smtp_port." ");
      $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
      if (!($this->sock && $this->smtp_ok())) {
        $this->log_write("Warning: Cannot connect to mx host ".$host." ");
        $this->log_write("Error: ".$errstr." (".$errno.") ");
        continue;
      }
      $this->log_write("Connected to mx host ".$host." ");
      return TRUE;
    }
    $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).") ");
    return FALSE;
  }
  function smtp_message($header, $body)
  {
    fputs($this->sock, $header." ".$body);
    $this->smtp_debug("> ".str_replace(" ", " "."> ", $header." > ".$body." > "));
    return TRUE;
  }
  function smtp_eom()
  {
    fputs($this->sock, " . ");
    $this->smtp_debug(". [EOM] ");
    return $this->smtp_ok();
  }
  function smtp_ok()
  {
    $response = str_replace(" ", "", fgets($this->sock, 512));
    $this->smtp_debug($response." ");
    if (!ereg("^[23]", $response)) {
      fputs($this->sock, "QUIT ");
      fgets($this->sock, 512);
      $this->log_write("Error: Remote host returned "".$response."" ");
      return FALSE;
    }
    return TRUE;
  }
  function smtp_putcmd($cmd, $arg = "")
  {
    if ($arg != "") {
      if($cmd=="") $cmd = $arg;
      else $cmd = $cmd." ".$arg;
    }
    fputs($this->sock, $cmd." ");
    $this->smtp_debug("> ".$cmd." ");
    return $this->smtp_ok();
  }
  function smtp_error($string)
  {
    $this->log_write("Error: Error occurred while ".$string.". ");
    return FALSE;
  }
  function log_write($message)
  {
    $this->smtp_debug($message);
    if ($this->log_file == "") {
      return TRUE;
    }
    $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
    if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
      $this->smtp_debug("Warning: Cannot open log file "".$this->log_file."" ");
      return FALSE;;
    }
    flock($fp, LOCK_EX);
    fputs($fp, $message);
    fclose($fp);
    return TRUE;
  }
  function strip_comment($address)
  {
    $comment = "([^()]*)";
    while (ereg($comment, $address)) {
      $address = ereg_replace($comment, "", $address);
    }
    return $address;
  }
  function get_address($address)
  {
    $address = ereg_replace("([ ])+", "", $address);
    $address = ereg_replace("^.*<(.+)>.*$", "1", $address);
    return $address;
  }
  function smtp_debug($message)
  {
    if ($this->debug) {
    echo $message;
    }
  }
}
?>


共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 .