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 本文中如有圖片,請用絕對路徑的引用 "yun_qi_img/image.gif";
並連上網,以保證程式能讀取到圖片的資料資訊
假如是通過表單提交過來的 Html 本文,請先用 StripSlashes($html_body) 把本文內容進行預先處理
Html 中用到的樣式表檔案,請不要用 <link >之類 的引用,直接把樣式表定義放在
<style></style>標籤中
*************************************/
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 rn"))
{
$this->err_str="無法發送命令".$command;
return false;
}
else
{
$resp=fgets($this->connection,256);
if($this->debug)
$this->outdebug("$resp");