奇怪的现象:SMTP发不出邮件

时间: 2009-10-06 / 分类: 网站制作技术 / 浏览次数: 2,577 views / 0个评论 发表评论

自从商中的邮箱升级后,植提空间论坛的发信功能就不能用了

测试了很多次都提示无错误

但是邮箱就是收不到信

今天用第3方的类测试了一下,惊奇地发现其实是可以发信的

类如下:

<?
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.”\n”;????
? $All???????????????????? .=?? “To:”.$this->to.”\n”;????
? $All???????????????????? .=?? “Subject:”.$this->subject.”\n”;????
? $All???????????????????? .=?? $this->body;????
? /*????
????? 如果把$All的内容再加处理,就可以实现发送MIME邮件了????
????? 不过还需要加很多程序????
? */????
???
???
? //以下是和服务器会话????
? $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: $from”.”\r\n”;????
? $this->docommand();????
???
? $this->in?????????????? =???? “RCPT?? TO: $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(“客户机命令:”.$this->in);????
? $this->result_str?? =?? “服务器应答:<font?? color=#cc0000>”.socket_read?? ($this->socket,?? 1024).”</font>”;????
? $this->debug_show($this->result_str);????
? }?
? }????
? $smtp???? =?????? new?? smtp_mail(“smtp.xxx.com”,”25″,”service@xxx.com”,”111111″,true);????
? $smtp->send(“service@xxx.com”,”xxx@xxx.com”,”shoudaomei”,”haohaohao”);??
? ?>

由此可断定DZ的发送代码有问题,至少针对现在使用的STMP服务器来说有问题

仔细查找错误后

发现只要将include/sendmail.inc.php里约43行的From: $email_from{$maildelimiter}去掉就能正常发信了

原来代码如下

$headers = “From: $email_from{$maildelimiter}MIME-Version: 1.0{$maildelimiter}Content-type: text/plain; charset=$charset{$maildelimiter}Content-Transfer-Encoding: base64{$maildelimiter}”;

发表评论

你必须 登录后 才能留言!