找一个不需要认证的smtp服务器
解决方案 »
- php开源门户及论坛,欢迎大家关顾!
- 懂JavaScript高手来.....................
- 请叫一下php什么时候用到类
- php结合DW MX打造站内搜索?
- 请问,php中==和===有什么区别?
- 我看见现在很多网页的编码都是用的utf-8 急问这是怎么实现的?我现在需要用UTF-8的编码显示繁体字.
- 为什么启动时提示找不到php_sybase_ct.dll和php_iconv.dll?急,送100分!!!
- 做了个在线显示,请问怎样让一行显示指定的人数?
- funnu快来拿份
- H5页面底部输入框点击弹出键盘,键盘遮住输入框怎么解决 ios android 兼容问题
- 这个函数对吗?
- 到底错在哪?
{
var $host = '127.0.0.1'; // SMTP主机名
var $port = 25; // 主机的smtp端口,一般是25号端口
var $timeout = 5; // 连接主机的最大超时时间
var $debug = 0; // 做为标识,是否在调试状态,是的话,输出调试信息
var $showerr = true;
var $handle;function Mail_SMTP($server = '127.0.0.1', $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."<br>";
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("/(?<!\r)\n/si", "\r\n", $header); $header_array = explode("\r\n", $header);
@reset($header_array);
$headers = "";
while( list(, $header) = each($header_array)){
if ( preg_match("/^from:/si", $header)){
$from = preg_replace("/^from:(.*)/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("/(?<!\r)\n/si", "\r\n", $body); if(trim($to) == ""){
$this->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