[/我的页面显示 :unable to authenticate to smtp server color]不知道什么原因,上网也看了别人的发的这个错误.,但很少,别人也贴了解决办法,但我没看到适合我的.所以来求高手帮解决! 在我的SMTP。PHP下有这个,我邮箱的用户密码都对的哦。但我不知道什么原因哦。艾。。求高手指点。         if ($this->auth) { 
            $method = is_string($this->auth) ? $this->auth : '';             if (PEAR::isError($smtp->auth($this->username, $this->password, 
                              $method))) { 
                return PEAR::raiseError('unable to authenticate to smtp server'); 
            } 
        } 
[color=#FF6600]另外代码如下: 
Main/smtp.php 
<?php class Mail_smtp extends Mail {     /** 
    * The SMTP host to connect to. 
    * @var string 
    */ 
    var $host = 'localhost';     /** 
    * The port the SMTP server is on. 
    * @var integer 
    */ 
    var $port = 25;     /** 
    * Should SMTP authentication be used? 
    * 
    * This value may be set to true, false or the name of a specific 
    * authentication method. 
    * 
    * If the value is set to true, the Net_SMTP package will attempt to use 
    * the best authentication method advertised by the remote SMTP server. 
    * 
    * @var mixed 
    */ 
    var $auth = true;     /** 
    * The username to use if the SMTP server requires authentication. 
    * @var string 
    */ 
    var $username = '';     /** 
    * The password to use if the SMTP server requires authentication. 
    * @var string 
    */ 
    var $password = '';     /** 
    * Hostname or domain that will be sent to the remote SMTP server in the 
    * HELO / EHLO message. 
    * 
    * @var string 
    */ 
    var $localhost = 'localhost';     /** 
    * Whether to use VERP or not. If not a boolean, the string value 
    * will be used as the VERP separators. 
    * 
    * @var mixed boolean or string 
    */ 
    var $verp = false;     /** 
    * Turn on Net_SMTP debugging? 
    * 
    * @var boolean $debug 
    */ 
    var $debug = false;     /** 
    * Constructor. 
    * 
    * Instantiates a new Mail_smtp:: object based on the parameters 
    * passed in. It looks for the following parameters: 
    *    host        The server to connect to. Defaults to localhost. 
    *    port        The port to connect to. Defaults to 25. 
    *    auth        SMTP authentication.  Defaults to none. 
    *    username    The username to use for SMTP auth. No default. 
    *    password    The password to use for SMTP auth. No default. 
    *    localhost  The local hostname / domain. Defaults to localhost. 
    *    verp        Whether to use VERP or not. Defaults to false. 
    *    debug      Activate SMTP debug mode? Defaults to false. 
    * 
    * If a parameter is present in the $params array, it replaces the 
    * default. 
    * 
    * @param array Hash containing any parameters different from the 
    *              defaults. 
    * @access public 
    */ 
    function Mail_smtp($params) 
    { 
        if (isset($params['host'])) $this->host = $params['host']; 
        if (isset($params['port'])) $this->port = $params['port']; 
        if (isset($params['auth'])) $this->auth = $params['auth']; 
        if (isset($params['username'])) $this->username = $params['username']; 
        if (isset($params['password'])) $this->password = $params['password']; 
        if (isset($params['localhost'])) $this->localhost = $params['localhost']; 
        if (isset($params['verp'])) $this->verp = $params['verp']; 
        if (isset($params['debug'])) $this->debug = (boolean)$params['debug']; 
    }   
    function send($recipients, $headers, $body) 
    { 
        include_once './Net/SMTP.php';         if (!($smtp = &new Net_SMTP($this->host, $this->port, $this->localhost))) { 
            return PEAR::raiseError('unable to instantiate Net_SMTP object'); 
        }         if ($this->debug) { 
            $smtp->setDebug(true); 
        }         if (PEAR::isError($smtp->connect())) { 
            return PEAR::raiseError('unable to connect to smtp server ' . 
                                    $this->host . ':' . $this->port); 
        }         if ($this->auth) { 
            $method = is_string($this->auth) ? $this->auth : '';             if (PEAR::isError($smtp->auth($this->username, $this->password, 
                              $method))) { 
                return PEAR::raiseError('unable to authenticate to smtp server'); 
            } 
        }         $headerElements = $this->prepareHeaders($headers); 
        if (PEAR::isError($headerElements)) { 
            return $headerElements; 
        } 
        list($from, $text_headers) = $headerElements;         /* Since few MTAs are going to allow this header to be forged 
        * unless it's in the MAIL FROM: exchange, we'll use 
        * Return-Path instead of From: if it's set. */ 
        if (!empty($headers['Return-Path'])) { 
            $from = $headers['Return-Path']; 
        }         if (!isset($from)) { 
            return PEAR::raiseError('No from address given'); 
        }         $args['verp'] = $this->verp; 
        if (PEAR::isError($smtp->mailFrom($from, $args))) { 
            return PEAR::raiseError('unable to set sender to [' . $from . ']'); 
        }         $recipients = $this->parseRecipients($recipients); 
        if (PEAR::isError($recipients)) { 
            return $recipients; 
        }         foreach ($recipients as $recipient) { 
            if (PEAR::isError($res = $smtp->rcptTo($recipient))) { 
                return PEAR::raiseError('unable to add recipient [' . 
                                        $recipient . ']: ' . $res->getMessage()); 
            } 
        }         if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) { 
            return PEAR::raiseError('unable to send data'); 
        }         $smtp->disconnect(); 
        return true; 
    } } 

解决方案 »

  1.   

    Mail.php <?php require_once 'PEAR.php'; /** 
    * PEAR's Mail:: interface. Defines the interface for implementing 
    * mailers under the PEAR hierarchy, and provides supporting functions 
    * useful in multiple mailer backends. 

    * @access public 
    * @version $Revision: 1.9 $ 
    * @package Mail 
    */ 
    class Mail 
    {     function send($recipients, $headers, $body) 
        { 
            // if we're passed an array of recipients, implode it. 
            if (is_array($recipients)) { 
                $recipients = implode(', ', $recipients); 
            }         // get the Subject out of the headers array so that we can 
            // pass it as a seperate argument to mail(). 
            $subject = ''; 
            if (isset($headers['Subject'])) { 
                $subject = $headers['Subject']; 
                unset($headers['Subject']); 
            }         // flatten the headers out. 
            list(,$text_headers) = Mail::prepareHeaders($headers);         return mail($recipients, $subject, $body, $text_headers);     } 
        function prepareHeaders($headers) 
        { 
            $lines = array(); 
            $from = null;         foreach ($headers as $key => $value) { 
                if (strcasecmp($key, 'From') === 0) { 
                    include_once 'Mail/RFC822.php'; 
                    $parser = &new Mail_RFC822(); 
                    $addresses = $parser->parseAddressList($value, 'localhost', false); 
                    if (PEAR::isError($addresses)) { 
                        return $addresses; 
                    }                 $from = $addresses[0]->mailbox . '@' . $addresses[0]->host;                 // Reject envelope From: addresses with spaces. 
                    if (strstr($from, ' ')) { 
                        return false; 
                    }                 $lines[] = $key . ': ' . $value; 
                } elseif (strcasecmp($key, 'Received') === 0) { 
                    // Put Received: headers at the top.  Spam detectors often 
                    // flag messages with Received: headers after the Subject: 
                    // as spam. 
                    array_unshift($lines, $key . ': ' . $value); 
                } else { 
                    // If $value is an array (i.e., a list of addresses), convert 
                    // it to a comma-delimited string of its elements (addresses). 
                    if (is_array($value)) { 
                        $value = implode(', ', $value); 
                    } 
                    $lines[] = $key . ': ' . $value; 
                } 
            }         return array($from, join($this->sep, $lines) . $this->sep); 
        }     /** 
        * Take a set of recipients and parse them, returning an array of 
        * bare addresses (forward paths) that can be passed to sendmail 
        * or an smtp server with the rcpt to: command. 
        * 
        * @param mixed Either a comma-seperated list of recipients 
        *              (RFC822 compliant), or an array of recipients, 
        *              each RFC822 valid. 
        * 
        * @return array An array of forward paths (bare addresses). 
        * @access private 
        */ 
        function parseRecipients($recipients) 
        { 
            include_once 'Mail/RFC822.php';         // if we're passed an array, assume addresses are valid and 
            // implode them before parsing. 
            if (is_array($recipients)) { 
                $recipients = implode(', ', $recipients); 
            }         // Parse recipients, leaving out all personal info. This is 
            // for smtp recipients, etc. All relevant personal information 
            // should already be in the headers. 
            $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false); 
            $recipients = array(); 
            if (is_array($addresses)) { 
                foreach ($addresses as $ob) { 
                    $recipients[] = $ob->mailbox . '@' . $ob->host; 
                } 
            }         return $recipients; 
        } } 
    send.php <?php 
    require_once 'Mail.php'; 
    $host = trim($_POST["smtp"]); 
    $to = trim($_POST["to"]); 
    $from = trim($_POST["from"]); 
    $username = trim($_POST["username"]); 
    $password = trim($_POST["password"]); 
    $subject = trim($_POST["subject"]); 
    $cotent = trim($_POST["cotent"]); 
    $conf['mail'] = array( 
    'host' => $host, //smtp服务器地址 
    'auth' => true, //true表示smtp服务器需要验证,false不需要 
    'username' => $username, //用户名 
    'password' => $password //密码 
    ); 
    //发送邮件 
    $headers['From'] = $from; //发信地址 
    $headers['To'] = $to; //收信地址 
    $headers['Subject'] = $subject; //邮件标题 
    $mail_object = &Mail::factory('smtp', $conf['mail']); 
    //邮件正文 
    $body = $content; $mail_res = $mail_object->send($headers['To'], $headers, $body); //发送 
    if(PEAR::isError($mail_res)){ //检测错误 
    die($mail_res->getMessage()); 

    else{ 
    echo(" <script>alert('发送成功!');location.href='/'; </script>"); 
    } ?> 
      

  2.   

    如果你的smtp服务用的是163的。那就是你的账号有问题。如果你不是2007/10/几号忘记了 之前注册的 网易邮箱 就没有这个smtp服务如果是之后注册的 就是要开通随身邮 嘿嘿。(10元)那句话的意思是:该用户名以锁定。....
      

  3.   

    那我用126的也不行哦,我公司给我配的邮箱我在OUTLOOK上好用哦,但在这个里头就不好用哩....不过公司的服务器在美国.真没办法呢?忘大侠们解决.........
      

  4.   

    你如果要测试的话。问你的公司人员要这个 2007年10月前注册的 网易邮箱。其实你程序没有错。外国人写的class还有问题啊?
      

  5.   

    恩谢谢楼上各位,我找了07以前的163, 好发.但是个垃圾邮件哈哈.今天跟老板说了下.他不同意填写SMTP..,想问问有没别的方法发.我要做的这个邮件包含这些,要客户填写好了然后发给我们客户人员.
    recipient's address : 
    Name:
    password:
    Company:
    Address:
    Tel:
    Date of Purchase:
    Manufacturer:
    附件.
    在这个上面不许填SMTP,就是不通过SMTP来发了还是怎么搞. 我以前听说有个GMAIL.
    忘高手指点迷津.我才接触邮件这块功能...不打懂,谢谢...