SMTPsock应用--用php发邮件
时间:2007-02-17 来源:PHP爱好者
server_name可以用php自己的dns解析函数,
以下是核心演示,winNT,mail server is Imail,php3.0.6
需要修改php3.ini打开imap模块,在linux上要编译php --with-IMAP
<?php
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_domainn" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs ( $fp, "MAIL FROM: <$from>n" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs ( $fp, "RCPT TO: <$to>n" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs($fp,"DATAn");
fputs($fp,"To: $ton");
fputs($fp,"From: $fromn");
fputs($fp,"Subject: $subjectnn");
fputs($fp,"$messagenn.n");
fputs($fp, "QUITn" );
}
}
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";
?>
php爱好者站 http://www.phpfans.net Linux|Apache|IIS.
以下是核心演示,winNT,mail server is Imail,php3.0.6
需要修改php3.ini打开imap模块,在linux上要编译php --with-IMAP
<?php
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_domainn" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs ( $fp, "MAIL FROM: <$from>n" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs ( $fp, "RCPT TO: <$to>n" );
$output = fgets ( $fp, 2000 );
echo $output;
fputs($fp,"DATAn");
fputs($fp,"To: $ton");
fputs($fp,"From: $fromn");
fputs($fp,"Subject: $subjectnn");
fputs($fp,"$messagenn.n");
fputs($fp, "QUITn" );
}
}
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";
?>
php爱好者站 http://www.phpfans.net Linux|Apache|IIS.
相关阅读 更多 +