1.asp 发邮件的问题 |
为了防止某些用户利用系统自带的smtp服务器来发垃圾邮件导致服务器性能严重下降而影响其它用户网站的正常访问,故我司禁用了系统自带的smtp服务器,也就是说 CDOTS.NewMail 组件无法使用,取而代之我司的服务器安装了Jmail4.0,用户可用它来发邮件,此组件的具体使用方法请查阅相关文档说明。 Jmail4.0 文件下载 |
|
2.php 发邮件的问题 |
为了防止某些用户利用系统自带的smtp服务器来发垃圾邮件导致服务器性能严重下降而影响其它用户网站的正常访问,故我司禁用了系统自带的smtp服务器,也就是说 mail() 无法使用,用户可用下面的php程式来发邮件。 |
smtp.class.php =====================================================================================================================
set_time_limit(120); class smtp_mail { var $host; //主机 var $port; //端口 一般为25 var $user; //SMTP认证的帐号 var $pass; //认证密码 var $debug = false; //是否显示和服务器会话信息? var $conn; var $result_str; //结果 var $in; //客户机发送的命令 var $from_r; //真实的源信箱,一般与smtp服务器的用户名一样,否则可能由于smtp服务器的设置而发送不成功 var $mailformat=0; //邮件格式 0=普通文本 1=html邮件 function smtp_mail($host,$port,$user,$pass,$debug=false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册 if($this->socket) { $this->result_str = "创建SOCKET:".socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("初始化失败,请检查您的网络连接和参数"); } $this->conn = socket_connect($this->socket,$this->host,$this->port); if($this->conn) { $this->result_str = "创建SOCKET连接:".socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("初始化失败,请检查您的网络连接和参数"); } $this->result_str = "服务器应答:".socket_read ($this->socket, 1024).""; $this->debug_show($this->result_str);
}
function debug_show($str) { if($this->debug) { echo $str."
rn"; } }
function send($from,$to,$subject,$body) { if($from == "" || $to == "") { exit("请输入信箱地址"); } if($subject == "") $sebject = "无标题"; if($body == "") $body = "无内容";
$All = "From:".$from."rn"; $All .= "To:".$to."rn"; $All .= "Subject:".$subject."rn"; if($this->mailformat==1) $All.= "Content-Type: text/html;rn"; else $All .= "Content-Type: text/plain;rn"; $All .= "charset=gb2312rnrn"; $All .= $body; /* 如果把$All的内容再加处理,就可以实现发送MIME邮件了 不过还需要加很多程序 */
//以下是和服务器会话 $this->in = "EHLO HELOrn"; $this->docommand();
$this->in = "AUTH LOGINrn"; $this->docommand();
$this->in = $this->user."rn"; $this->docommand();
$this->in = $this->pass."rn"; $this->docommand(); if(!eregi("235",$this->result_str)){ $this->result_str = "smtp 认证失败"; $this->debug_show($this->result_str); return 0; }
$this->in = "MAIL FROM:".$from."rn"; $this->docommand();
$this->in = "RCPT TO:".$to."rn"; $this->docommand();
$this->in = "DATArn"; $this->docommand();
$this->in = $All."rn.rn"; $this->docommand();
if(!eregi("250",$this->result_str)){ $this->result_str = "邮件发送失败"; $this->debug_show($this->result_str); return 0; }
$this->in = "QUITrn"; $this->docommand();
//结束,关闭连接 return 1; }
function docommand() { socket_write ($this->socket, $this->in, strlen ($this->in)); $this->debug_show("客户机命令:".$this->in); $this->result_str = "服务器应答:".socket_read ($this->socket, 1024).""; $this->debug_show($this->result_str); }
} //end class ?>
mailtest.php =====================================================================================================================
include "smtp.class.php"; $smtpserver = "您的smtp服务器ip地址或域名"; $port = 25 ; //smtp服务器的端口,一般是 25 $smtpuser = "test@test.com"; //您登录smtp服务器的用户名 $smtppwd = "111111"; //您登录smtp服务器的密码 $smtp = new smtp_mail("$smtpserver","$port","$smtpuser","$smtppwd"); $from= "测试用户<test@test.com>"; //发件人,一般要与您登录smtp服务器的用户名($smtpuser)相同,否则可能会因为smtp服务器的设置导致发送失败 $to = "aaa@21cn.com"; $subject = "你好"; $smtp->mailformat=1;//发送HTML格式的邮件 ,如果 $smtp->mailformat=0 则是发送普通文本格式的邮件 $body = "
这是一个用 php socket 发邮件的测试。 支持SMTP论证! "; $send=$smtp->send($from,$to,$subject,$body); if($send==1){ echo "邮件发送成功"; }else{ echo "邮件发送失败 "; echo "原因:".$smtp->result_str; } ?>
php 发邮件的程式下载 |