一聚教程网:一个值得你收藏的教程网站

热门教程

PHP邮件专题

时间:2022-07-02 10:32:40 编辑:袖梨 来源:一聚教程网

PHP SMTP类

/***********************************
PHP MIME SMTP ver 1.0 Powered by Boss_ch, Unigenius soft ware co. Ltd
All rights reserved, Copyright 2000 ;
本类用 PHP 通过 smtp  sock 操作发送 MIME 类型的邮件,可以发送
HTML 格式的正文、附件,采用 base64 编码
本版本是针对个人的发送,与多人群发版本不同的是,每发送到一个人,就重新进行一次编码,在接收端的用户看来,只是发送给他一个人的。
针对多人群发的情况,只发送一次,通过多个 RCPT TO 命令发送到不同的人信箱中,
说明:
请把 $hostname 设为你有权限的 默认 smtp 服务器或是在 new 时指定
把 $charset 改成你的默认 字符集
Html 正文中如有图片,请用绝对路径的引用 "httP://host/path/image.gif";
  并连上网,以保证程序能读取到图片的数据信息
假如是通过表单提交过来的 Html 正文,请先用 StripSlashes($html_body) 把正文内容进行预处理
  Html 中用到的样式表文件,请不要用 之类 的引用,直接把样式表定义放在
标签中

*************************************/
if(!isset($__smtp_class__)){
$__smtp_class__=1;

class smtp
{
var $hostname="";
var $port=25;
var $connection=0;
var $debug=1;

var $timeout=30;
var $err_str;
var $err_no;

var $autocode=true;
var $charset="??????";
var $subject="";
var $body="";
var $attach="";
var $temp_text_body;
var $temp_html_body;
var $temp_body_images;

var $bound_begin="=====powered_by_boss_chen_";
var $bound_end="_046484063883_=====";

Function smtp($server="smtp.china.com",$port=25,$time_out=20)
{$this->hostname=$server;
$this->port=$port;
$this->timeout=$time_out;
return true;
}

Function outdebug($message)
{
echo htmlspecialchars($message)."
n";
}


function command($command,$return_lenth=1,$return_code='2')
{
if ($this->connection==0)
{
$this->err_str="没有连接到任何服务器,请检查网络连接";
return false;
}
if ($this->debug)
$this->outdebug(">>> $command");
if (!fputs($this->connection,"$command rn"))
{
$this->err_str="无法发送命令".$command;
return false;
}
else
{
$resp=fgets($this->connection,256);
if($this->debug)
$this->outdebug("$resp");

热门栏目