建议你下个IPB的程序,看它的Mail类。
如果想用mail函数,弄个smtp服务器就可以了

解决方案 »

  1.   

    在window下使用MAIL函数要正确的设置SMTP服务器,
    而现在的大多数SMTP服务器都需要身份验证,所以简单的使用MAIL函数是不行的
    通常的解决办法就是使用SOCKET发信。
    phpe.net上有很多使用SOCKET发信的CLASS
    使用方法里面都有例子。一看就会明白的。
      

  2.   

    我也很少用,只是前段时间弄过,说一些经验,也不是很了解:)
    如果用mail函数,必须在php.ini里设置smtp服务器,比如smtp.163.com(举例而已,不一定可用),只要是smtp服务器可用就行了,这样就能发邮件了~~或者你自己装个邮件服务器。
    用Socket发送电子邮件的话,我没做过,但是IPB的Mail类里有,可以直接用 function smtp_send_mail()
    {
    $this->smtp_fp = fsockopen( $this->smtp_host, intval($this->smtp_port), $errno, $errstr, 30 );

    if ( ! $this->smtp_fp )
    {
    $this->smtp_error("Could not open a socket to the SMTP server");
    }

    $this->smtp_get_line();

    $this->smtp_code = substr( $this->smtp_msg, 0, 3 );

    if ( $this->smtp_code == 220 )
    {
    $data = $this->smtp_crlf_encode( $this->mail_headers."\n" . $this->message);

    //---------------------
    // HELO!, er... HELLO!
    //---------------------

    $this->smtp_send_cmd("HELO ".$this->smtp_host);

    if ( $this->smtp_code != 250 )
    {
    $this->smtp_error("HELO");
    }

    //---------------------
    // Do you like my user!
    //---------------------

    if ($this->smtp_user and $this->smtp_pass)
    {
    $this->smtp_send_cmd("AUTH LOGIN");

    if ( $this->smtp_code == 334 )
    {
    $this->smtp_send_cmd( base64_encode($this->smtp_user) );

    if ( $this->smtp_code != 334  )
    {
    $this->smtp_error("Username not accepted from the server");
    }

    $this->smtp_send_cmd( base64_encode($this->smtp_pass) );

    if ( $this->smtp_code != 235 )
    {
    $this->smtp_error("Password not accepted from the server");
    }
    }
    else
    {
    $this->smtp_error("This server does not support authorisation");
    }
    }

    //---------------------
    // We're from MARS!
    //---------------------

    if ( $this->wrap_brackets )
    {
    if ( ! preg_match( "/^</", $this->from ) )
    {
    $this->from = "<".$this->from.">";
    }
    }

    $this->smtp_send_cmd("MAIL FROM:".$this->from);

    if ( $this->smtp_code != 250 )
    {
    $this->smtp_error();
    }

    $to_arry = array( $this->to );

    if ( count( $this->bcc ) > 0 )
    {
    foreach ($this->bcc as $bcc)
    {
    if ( preg_match( "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/", str_replace( " ", "", $bcc ) ) )
    {
    $to_arry[] = $bcc;
    }
    }
    }

    //---------------------
    // You are from VENUS!
    //---------------------

    foreach( $to_arry as $to_email )
    {
    if ( $this->wrap_brackets )
    {
    $this->smtp_send_cmd("RCPT TO:<".$to_email.">");
    }
    else
    {
    $this->smtp_send_cmd("RCPT TO:".$to_email);
    }

    if ( $this->smtp_code != 250 )
    {
    $this->smtp_error("Incorrect email address: $to_email");
    return;
    break;
    }
    }

    //---------------------
    // SEND MAIL!
    //---------------------

    $this->smtp_send_cmd("DATA");

    if ( $this->smtp_code == 354 )
    {
    //$this->smtp_send_cmd( $data );
    fputs( $this->smtp_fp, $data."\r\n" );
    }
    else
    {
    $this->smtp_error("Error on write to SMTP server");
    }

    //---------------------
    // GO ON, NAFF OFF!
    //---------------------

    $this->smtp_send_cmd(".");

    if ( $this->smtp_code != 250 )
    {
    $this->smtp_error();
    return;
    }

    $this->smtp_send_cmd("quit");

    if ( $this->smtp_code != 221 )
    {
    $this->smtp_error();
    return;
    }

    //---------------------
    // Tubby-bye-bye!
    //---------------------

    @fclose( $this->smtp_fp );
    }
    else
    {
    $this->smtp_error();
    }
    }
      

  3.   

    to: countstars(深空) 但是IPB的Mail类里有,可以直接用请问countstars(深空) 哪些代码放在哪个位置,我放在PHP.ini里不可以。期待中
      

  4.   

    晕.....
    这是PHP代码,怎么可能放到配置文件里呢.
    应该放到你要调用的地方
    countstars(深空)给的这个函数是类的一个方法,不能直接使用
    需要将该类包含才行
      

  5.   

    拿别人的东西虽然快,最好还是弄清楚原理,如果打算使用socket发送,去看看smtp的发送过程如何,了解了之后,什么都容易了!
      

  6.   

    晕.....
    这是PHP代码,怎么可能放到配置文件里呢.
    应该放到你要调用的地方
    countstars(深空)给的这个函数是类的一个方法,不能直接使用
    需要将该类包含才行还是用类phpmailer
      

  7.   

    类phpmailer是什么东东,有实例介绍吗?
      

  8.   

    给你个地址你下载吧:
    http://www.mnrc.com.cn/phpmailer.zip
    或者
    http://www.fzc.cn/phpmailer.zip
      

  9.   

    错了,错了,是下面这个地址
    http://freeweb.nyist.net/~hxt/wen/phpmailer.zip
      

  10.   

    有个phpmailer,直接使用就可以了。很简单。
      

  11.   

    那个类是一个php文件,你要引用这个类,就必须先将这个类实例化,然后引用..