<?php
/*
*版本:1.4.2
*作者:鱼尾唯一
*主页:www.fishwei.com
*QQ群:33918040 有付出才会有收获!
*联系:bakjing@163.com (MSN/E-mail) 14778648(QQ)
*描述:利用socket套接字+SMTP指令编写的mail()函数,由本群 古董 同志指导 o(∩_∩)o...哈哈
*改进:1.1->使发送的邮件支持HTML,但是貌似不支持CSS!通过设定$htmlsupport=0,取消对HTML支持,默认为支持!
1.2->a.添加了 $mailfrom 参数,原因-仅仅靠smtp地址判断是不准确的!
b.发信时间修改成了脚本执行时的服务器时间
c.添加为HTML格式的新建提供了编码设置
1.3->修改了错误提示,格式为错误步骤+错误代码+错误描述!
1.4->支持邮件群发,多个邮件用分号隔开,根据 No.1 的意见,修改了部分冗余代码!
*/
function mail_error_report($content,$errno,$error,$adv=""){
$adv = $adv?("<b>提 示:</b>".$adv):$adv;
return "<b>出 错 啦!</b><br />
<b>错误步骤:</b>".$content."<br />
<b>错误代码:</b>".$errno."<br />
<b>错误描述:</b>".$error."<br />".$adv;
}
function socket_mail($smtphost,$name,$psw,$mailfrom,$mailtos,$mail_subject,$mail_content,$htmlsupport=1,$charset="GBK",$smtpport=25){
$fp = @fsockopen($smtphost, $smtpport, $errno, $error, 10);
if (!$fp){
echo mail_error_report("打开到".$smtphost."SMTP服务器的连接",$errno,$error,"请核查SMTP服务器名,网络连接情况,以及是否有防火墙阻止!");
return false;
}else{
$content = fgets($fp, 200);
fwrite($fp, "helo $name\n");
$content = fgets($fp,200);
$errno = intval(substr($content,0,3));
$error = substr($content,4,200);
if($errno==250){
fwrite($fp, "auth login\n");
$content = fgets($fp,200);
$errno = intval(substr($content,0,3));
$error = substr($content,4,200);
}else{
return mail_error_report("用户有效性验证",$errno,$error);
}
if($errno==334){
fwrite($fp, (base64_encode($name))."\n");
$content = fgets($fp,200);
$errno = intval(substr($content,0,3));
$error = substr($content,4,200);
}else{
return mail_error_report("登录命令",$errno,$error);
}
if($errno==334){
fwrite($fp, (base64_encode($psw))."\n");
$content = fgets($fp,200);
$errno = intval(substr($content,0,3));
$error = substr($content,4,200);
}else{
return mail_error_report("用户名验证",$
|