日期:2014-05-17 浏览次数:20803 次
if(!$fp=fsockopen($this->smtp['host'],$this->smtp['port'],$errno,$errstr)){ $this->message[]="连接邮件服务器失败,请检查:\r\n1、服务器地址和端口是否设置正确!\r\n2、网络是否通畅!"; return false; } if(strncmp(fgets($fp,512),'220',3)!=0){ $this->message[]="连接邮件服务器失败,请检查:\r\n1、服务器地址和端口是否设置正确!\r\n2、网络是否通畅!"; return false; } if($this->smtp['auth']){ fwrite($fp,"EHLO ".$this->smtp['posthost']."\r\n"); while($rt=strtolower(fgets($fp,512))){ if(strpos($rt,"-")!==3 || empty($rt)){ break; }elseif(strpos($rt,"2")!==0){ $this->message="与服务器招呼握手时错误"; return false; } } fwrite($fp, "AUTH LOGIN\r\n"); if(strncmp(fgets($fp,512),'334',3)!=0){ $this->message="提示服务器要登陆验证时错误"; return false; } fwrite($fp, base64_encode($this->smtp['user'])."\r\n"); if(strncmp(fgets($fp,512),'334',3)!=0){ $this->message="SMTP AUTH LOGIN 验证 用户名 错误!"; return false; } fwrite($fp, base64_encode($this->smtp['pass'])."\r\n"); if(strncmp(fgets($fp,512),'235',3)!=0){ $this->message="SMTP AUTH LOGIN 验证 密码 错误!"; return false; } } else{ fwrite($fp, "HELO ".$this->smtp['posthost']."\r\n"); } $from = $this->smtp['from']; $from = preg_replace("/.*\<(.+?)\>.*/", "\\1", $from); fwrite($fp, "MAIL FROM: <$from>\r\n"); if(strncmp(fgets($fp,512),'250',3)!=0){ $this->message="发信人地址错误!"; return false; } fwrite($fp, "RCPT TO: <$toemail>\r\n"); if(strncmp(fgets($fp,512),'250',3)!=0){ $this->message="收信人地址错误!"; return false; } fwrite($fp, "DATA\r\n"); if(strncmp(fgets($fp,512),'354',3)!=0){ $this->message="邮件数据发送失败!"; return false; } $msg = "Date: ".date("r")."\r\n"; $msg .= "Subject: $send_subject\r\n"; $msg .= "$additional\r\n"; $msg .= "$send_message\r\n.\r\n"; fwrite($fp, $msg); $lastmessage = fgets($fp, 512); if(substr($lastmessage, 0, 3) != 250