connect('name','pass'); [/php] " />
麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
mail类使用中的问题,请帮忙
悬赏分:20 - 2007年05月29日

由于我本机没有smtp,我使用smtp的时候,就是采用了网易163的 代码如下 [php]include_once ("email.php"); $sendmail = new Mail_SMTP("smtp.163.com","25","5"); $sendmail->connect('name','pass'); [/php] name是我的用户名,我的真实用户名没有写在上面 pass是我的密码 email.php是一个mail类,代码如下, 我哪里错了? 他总是提示我: Ran into problems sending Mail. Response: 550 : Invalid User 我用户应该没有错呀,我可以直接登录的~ [php]<? class Mail_SMTP { var $host = 'smtp.163.com'; // SMTP主机名 var $port = 25; // 主机的smtp端口,一般是25号端口 var $timeout = 5; // 连接主机的最大超时时间  var $debug = 0; // 做为标识,是否在调试状态,是的话,输出调试信息 var $showerr = true; var $handle; function Mail_SMTP($server = 'smtp.163.com', $port = 25, $time_out = 5){ $this ->host = $server; $this ->port = $port; $this ->timeout = $time_out; return true; } function errmsg($err,$show=false){ if ($this->showerr || $show){ echo $err."
"; exit(); } } function _command($cmd, $response){ if (!(fputs($this->handle,$cmd . "\r\n"))){ $this->errmsg("Couldn't send command to server"); return false; } while ( substr($server_response,3,1) != ' ' ){ if( !( $server_response = fgets($this->handle, 256))){ $this->errmsg("Couldn't get mail server response codes"); } } if( !( substr($server_response, 0, 3) == $response )){ $this->errmsg( "Ran into problems sending Mail. Response: $server_response"); } } function connect($user = '',$pass = ''){ if( !$this->handle = fsockopen($this->host, 25, $errno, $errstr, 20)){ $this->errmsg( "Could not connect to smtp host : $errno : $errstr"); } $r = fgets($this->handle, 256); if ( substr($r, 0, 3) != "220"){ $this->errmsg("couldn't connection to smtp server"); return false; } if( $user != '' && $pass != ''){ // Send the RFC2554 specified EHLO. // This improved as provided by SirSir to accomodate // both SMTP AND ESMTP capable servers $this->_command("EHLO \"" . $this->host . "\"", "250"); $this->_command("AUTH LOGIN","334"); $this->_command(base64_encode($user), "334"); $this->_command(base64_encode($pass), "235"); } else{ // Send the RFC821 specified HELO. $this->_command("HELO \"" . $this->host . "\"", "250"); } } function sendmail($header, $body = ''){ //header if (isset($header)){ if(is_array($header)){ if(sizeof($header) > 1){ $header = join("\r\n", $header); } else{ $header = $header[0]; } } $header = chop($header); $header = preg_replace("/(?.*)/si", "\\1", $header); } elseif ( preg_match("/^to:/si", $header)){ $to = preg_replace("/^to.*)/si", "\\1", $header); } elseif ( preg_match("/^subject:/si", $header)){ $subject = preg_replace("/^subject.*)/si", "\\1", $header); } elseif ( preg_match("/^cc:/si", $header)){ $cc = preg_replace("/^cc.*)/si", "\\1", $header); } elseif( preg_match("/^bcc:/si", $header )){ $bcc = preg_replace("/^bcc.*)/si", "\\1", $header); $header = ""; continue; } $headers .= $header . "\r\n"; } $headers = chop($headers); } //body $body = preg_replace("/(?errmsg("No email address specified"); } if(trim($subject) == ""){ $this->errmsg( "No email Subject specified"); } $to = explode(",", $to); $cc = explode(",", $cc); $bcc = explode(",", $bcc); $this->_command("MAIL FROM: " . $from, "250"); @reset( $to ); while( list( , $to_address ) = each( $to )){ $to_address = trim($to_address); if ( preg_match('/[^ ]+\@[^ ]+/', $to_address)){ $this->_command("RCPT TO: <$to_address>", "250"); } } // Ok now do the CC and BCC fields... @reset( $bcc ); while( list( , $bcc_address ) = each( $bcc )){ $bcc_address = trim( $bcc_address ); if ( preg_match('/[^ ]+\@[^ ]+/', $bcc_address)){ $this->_command("RCPT TO: <$bcc_address>", "250"); } } @reset( $cc ); while( list( , $cc_address ) = each( $cc )){ $cc_address = trim( $cc_address ); if ( preg_match('/[^ ]+\@[^ ]+/', $cc_address)){ $this->_command("RCPT TO: <$cc_address>", "250"); } } // Ok now we tell the server we are ready to start sending data $this->_command("DATA", "354"); $bodys = $headers . "\r\n\r\n" . $body . "\r\n"; fputs($this->handle, $bodys); $this->_command("\r\n.", "250"); return TRUE; } function quit(){ // Now tell the server we are done and close the socket... fputs($this->handle, "QUIT\r\n"); fclose($this->handle); } }//end class ?>[/php]

提问者:gouki   05-29 15:03
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
38 + 21 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM