程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> SMTPsock應用--用php發郵件

SMTPsock應用--用php發郵件

編輯:關於PHP編程

server_name可以用php自己的dns解析函數,
以下是核心演示,winNT,mail server is Imail,php3.0.6
需要修改php3.ini打開imap模塊,在linux上要編譯php --with-IMAP

function send_email ( $to,$from,$subject,$message ){
global $SERVER_NAME;
$fp = fsockopen ( $SERVER_NAME, 25 );
if ( $fp ){

echo "connected";

set_socket_blocking( $fp, false );
$output=fgets($fp,2500);

echo $output;

if (! ereg ( "^220", $output ) ) {
exit();
} else {

echo "talking ";

//set_socket_blocking ( $fp, true );
fputs ( $fp, "HELO $from_domain " );
$output = fgets ( $fp, 2000 );

echo $output;

fputs ( $fp, "MAIL FROM: <$from> " );
$output = fgets ( $fp, 2000 );

echo $output;

fputs ( $fp, "RCPT TO: <$to> " );
$output = fgets ( $fp, 2000 );

echo $output;

fputs($fp,"DATA ");
fputs($fp,"To: $to ");
fputs($fp,"From: $from ");
fputs($fp,"Subject: $subject ");
fputs($fp,"$message . ");
fputs($fp, "QUIT " );
}
}
fclose($fp);
}

$SERVER_NAME="127.0.0.1";
$from_domain="ws";
$to=" [email protected] ";
$from=" [email protected] ";
$subject="test SMTP through PHP 中文";
$message="Send email via PHP smtp connectionsnnnothing happenesn 中文
中文中文";

send_email ( $to,$from,$subject,$message );
echo "ok lah";
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved