Home  >  Article  >  Backend Development  >  SMTPsock Application--Sending Emails with PHP_PHP Tutorial

SMTPsock Application--Sending Emails with PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:23:14981browse

server_name can use PHP's own dns resolution function,
The following is the core demonstration, winNT, mail server is Imail,php3.0.6
You need to modify php3.ini to open the imap module, and compile php on Linux --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: " );
$output = fgets ( $fp, 2000 );

echo $output;

fputs ( $fp, "RCPT 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=" daiger@xifeng.com ";
$from=" wangsu@xifeng.com ";
$subject="test SMTP through PHP Chinese";
$message="Send email via PHP smtp connectionsnnnothing happens 中文
中文中文";

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532246.htmlTechArticleserver_name can use php's own dns resolution function. The following is the core demonstration, winNT, mail server is Imail,php3. 0.6 You need to modify php3.ini to open the imap module. On Linux, you need to compile php --with-IMAP...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn