一个牛人的代码,php发邮件的!不用fsocket 1、$this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册 谁说不用socket 2、此代码没有错误,早就测试通过了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有socket怎么可能跟Email服务器通信? 有socket,是我写错了。。好象是没有fsockopen。。各位帮忙看下吧,怎么改 这个函数不错,挺好用,我又在此基础上简单的完善了一下,主要是可以支持html代码但是我在本地xp机器上测试,服务器应答出现错误,在unix服务器上就正常,有人能告诉我是怎么回事吗?下面是应答错误:客户机命令:DATA 服务器应答:503 No sender. 客户机命令:From:iamwh<[email protected]> To:[email protected] Subject:test MIME-Version: 1.0 Content-type: text/html; charset=gb2312 内容 . 服务器应答:502 CoremailSys:Error: command not implemented 客户机命令:QUIT 服务器应答:502 CoremailSys:Error: command not implemented <?php/* 作者:小露珠3.3 QQ:6550382 * 日期:2003-09-18 请尊重别人的劳动成功,请保留此版权信息,谢谢! 作者:小露珠3.3 ,欢迎和我联系交流PHP QQ6550382 MAIL:[email protected] 修改时间 :2005-2-25 修改内容 :可以发送html格式的邮件MAIL: [email protected]*/ 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; //源信箱 var $to; //目标信箱 var $subject; //主题 var $body; //内容 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 = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if($this->debug) { echo $str."<p>\r\n"; } } function send($from,$to,$subject,$body) { if($from == "" || $to == "") { exit("请输入信箱地址"); } if($subject == "") $sebject = "无标题"; if($body == "") $body = "无内容"; $this->from = $from; $this->to = $to; $this->subject = $subject; $this->body = $body; $All .= "From:".$this->from."\r\n"; $All .= "To:".$this->to."\r\n"; $All .= "Subject:".$this->subject."\r\n"; $All .= "MIME-Version: 1.0\r\n"; $All .= "Content-type: text/html; charset=gb2312\r\n"; $All .= "\r\n"; $All .= $this->body; $All .= "\r\n"; //以下是和服务器会话 $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user."\r\n"; $this->docommand(); $this->in = $this->pass."\r\n"; $this->docommand(); $this->in = "MAIL FROM:".$this->from."\r\n"; $this->docommand(); $this->in = "RCPT TO:".$this->to."\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All."\r\n.\r\n"; $this->docommand(); $this->in = "QUIT\r\n"; $this->docommand(); //结束,关闭连接 } function docommand() { socket_write ($this->socket, $this->in, strlen ($this->in)); $this->debug_show("客户机命令:".htmlspecialchars($this->in)); $this->result_str = "服务器应答:<font color=#cc0000>"; $this->result_str .= socket_read($this->socket,1024); $this->result_str .= "</font>"; $this->debug_show($this->result_str); } } ?> 底层协议都是要通过socket通信的. 如何获取文件的文件流 如何在虚拟机2003下安装PHP开发环境,等软件,新手求教 关于PHP中的一个问题 使用PHP空间中遇到的一个问题 无法获取$_SERVER["HTTP_REFERER"] PHP多维数组的排序问题!请教! 怎么在apache服务器配置自动识别大小写? CSDN群英荟萃,难道连php操作oralce的blob也没有人指教么?如果帮我解决,给你五百分! form中变量的传值问题? PHP先声明类后创建对象 和 先创建对象后声明类 mysql的SELECT语句支持子查询吗? 问题急!路过的请进来坐坐!。。。。。。。。。。。。。
各位帮忙看下吧,怎么改
但是我在本地xp机器上测试,服务器应答出现错误,在unix服务器上就正常,有人能告诉我是怎么回事吗?
下面是应答错误:客户机命令:DATA
服务器应答:503 No sender. 客户机命令:From:iamwh<[email protected]> To:[email protected] Subject:test MIME-Version: 1.0 Content-type: text/html; charset=gb2312 内容 .
服务器应答:502 CoremailSys:Error: command not implemented 客户机命令:QUIT
服务器应答:502 CoremailSys:Error: command not implemented <?php
/* 作者:小露珠3.3 QQ:6550382
* 日期:2003-09-18
请尊重别人的劳动成功,请保留此版权信息,谢谢!
作者:小露珠3.3 ,欢迎和我联系交流PHP QQ6550382
MAIL:[email protected] 修改时间 :2005-2-25
修改内容 :可以发送html格式的邮件
MAIL: [email protected]
*/
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; //源信箱
var $to; //目标信箱
var $subject; //主题
var $body; //内容
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 = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
$this->debug_show($this->result_str);
}
function debug_show($str)
{
if($this->debug)
{
echo $str."<p>\r\n";
}
}
function send($from,$to,$subject,$body)
{
if($from == "" || $to == "")
{
exit("请输入信箱地址");
}
if($subject == "") $sebject = "无标题";
if($body == "") $body = "无内容";
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
$All .= "From:".$this->from."\r\n";
$All .= "To:".$this->to."\r\n";
$All .= "Subject:".$this->subject."\r\n";
$All .= "MIME-Version: 1.0\r\n";
$All .= "Content-type: text/html; charset=gb2312\r\n";
$All .= "\r\n";
$All .= $this->body;
$All .= "\r\n";
//以下是和服务器会话
$this->in = "EHLO HELO\r\n";
$this->docommand();
$this->in = "AUTH LOGIN\r\n";
$this->docommand();
$this->in = $this->user."\r\n";
$this->docommand();
$this->in = $this->pass."\r\n";
$this->docommand();
$this->in = "MAIL FROM:".$this->from."\r\n";
$this->docommand();
$this->in = "RCPT TO:".$this->to."\r\n";
$this->docommand();
$this->in = "DATA\r\n";
$this->docommand();
$this->in = $All."\r\n.\r\n";
$this->docommand();
$this->in = "QUIT\r\n";
$this->docommand();
//结束,关闭连接
}
function docommand()
{
socket_write ($this->socket, $this->in, strlen ($this->in));
$this->debug_show("客户机命令:".htmlspecialchars($this->in));
$this->result_str = "服务器应答:<font color=#cc0000>";
$this->result_str .= socket_read($this->socket,1024);
$this->result_str .= "</font>";
$this->debug_show($this->result_str);
}
} ?>