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(); }
而现在的大多数SMTP服务器都需要身份验证,所以简单的使用MAIL函数是不行的
通常的解决办法就是使用SOCKET发信。
phpe.net上有很多使用SOCKET发信的CLASS
使用方法里面都有例子。一看就会明白的。
如果用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();
}
}
这是PHP代码,怎么可能放到配置文件里呢.
应该放到你要调用的地方
countstars(深空)给的这个函数是类的一个方法,不能直接使用
需要将该类包含才行
这是PHP代码,怎么可能放到配置文件里呢.
应该放到你要调用的地方
countstars(深空)给的这个函数是类的一个方法,不能直接使用
需要将该类包含才行还是用类phpmailer
http://www.mnrc.com.cn/phpmailer.zip
或者
http://www.fzc.cn/phpmailer.zip
http://freeweb.nyist.net/~hxt/wen/phpmailer.zip