首页 >后端开发 >php教程 >NT下基于邮件服务软件(IMAIL)的邮件发送程序--(网络版)_PHP

NT下基于邮件服务软件(IMAIL)的邮件发送程序--(网络版)_PHP

WBOY
WBOY原创
2016-06-01 12:42:391200浏览

IMail

如果你无法在服务器上安装IMAIL,那只能通过socket来发送邮件。但是如果你幸运的话,也可以用163/sina的

smtp服务。

例程如下(原程序由马毅兄提供):


Mail Form anywhere



if($sendit)
{
$smtpserver="202.110.200.242" ;        //将此处设为IMAIL的IP
echo "
" ;<br>
$fp = fsockopen($smtpserver, 25, &$errno, &$errstr, 10) ; //连接smtp服务器,端口25<br>
if(!$fp) die("wrong open smtp SERVER") ;<br>
$hostreplay=fgets($fp,128);<br>
//if (!strstr($hostreplay,"220")) die(" can n't receive the 220 answer ") ;<br>
$smailname=strstr(ltrim($hostreplay),"220 ") ;<br>
$smailname=substr($smailname,0,strpos($smailname,".")) ;<br>
//echo "\nsmailname:$smailname\n" ;<br>
fputs($fp,"$smailname \n") ;<br>
$hostreplay=fgets($fp,128);<br>
//if (!strstr($hostreplay,"250")) die(" can n't receive the 250 answer ") ;<br>
<br>
fputs($fp,"MAIL FROM: \n") ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"250")) {<br>
fputs($fp,"MAIL FROM: root\n") ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"250")) {<br>
fputs($fp,"MAIL FROM: root@263.net\n") ;<br>
echo($hostreplay=fgets($fp,128)) ;<br>
if (!strstr($hostreplay,"250")) {<br>
fputs($fp,"MAIL FROM: $from_address\n") ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"250")) die(" can n't receive the 250 answer ") ;<br>
};<br>
};<br>
};<br>
fputs($fp,"RCPT TO: $to_address\n") ;<br>
$hostreplay=fgets($fp,128);<br>
if (!strstr($hostreplay,"250")) {<br>
fputs($fp,"RCPT TO: $mailname\n") ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"250")) echo(" can n't receive the 354 answer") ;<br>
};<br>
fputs($fp,"DATA\n") ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"354")) die(" can n't receive the 250 answer ") ;<br>
$tosend="From: $from_address\n";<br>
$tosend.="To: $to_address\n";<br>
$tosend.="Subject:".str_replace("\N"," ",$subject)."\n你好,这是yukuang发给您的一封测试信!!<br>
<br>
\n.\n";<br>
fputs($fp,$tosend) ;<br>
$hostreplay=fgets($fp,128) ;<br>
if (!strstr($hostreplay,"250")) die(" can n't receive the 250 answer ") ;<br>
fputs($fp,"QUIT\n") ;<br>
fclose($fp) ;<br>
echo "发送成功";<br>
exit();<br>
//if($ck_name!='root') die("

bye bye ");

};

?>






























cn-bbs web meil

from


value="">
to
value="">
subject

c

o

n

t

e

n

t


















该程序在局域网内调试通过,我的IP是202.110.200.242,供大家测试
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn