首页 > 开发 > PHP > 正文

PHP邮件专题

2024-05-04 22:16:24
字体:
来源:转载
供稿:网友

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

转载请保留此版权信息,Bugs Report : [email]boss_ch@china.com[/email]
*************************************/
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)."<br>/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 /r/n"))
{
$this->err_str="无法发送命令".$command;
return false;
}
else
{
$resp=fgets($this->connection,256);
if($this->debug)
$this->outdebug("$resp");
if (substr($resp,0,$return_lenth)!=$return_code)
{
$this->err_str=$command." 命令服务器返回无效:".$resp;
return false;
}
else
return true;
}
}


Function open()
{
if($this->hostname=="")
{$this->err_str="无效的主机名!!";
return false;
}

if ($this->debug) echo "$this->hostname,$this->port,&$err_no, &$err_str, $this->timeout<BR>";
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表