答案:复制代码 代码如下:
<?php
/*
* php smtp发送邮件Scoket类
* ZhozPhpSmtpSendMail.php
* Created on 2008/09/02 zhoz.com
* @author zhoz
* v 1.72 update 2008/09/26 zhoz.Com
*/
class ZhozPhpSmtpSendMail {
//您的SMTP 服务器供应商,可以是域名或IP地址
var $smtp = "";
//SMTP需要要身份验证设值为 1, 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
var $check = 1;
//您的email帐号名称
var $username = "";
//您的email密码
var $password = "";
//此email 必需是发信服务器上的email
var $s_from = "";
/*
* 功能:发信初始化设置
* $from 你的发信衿魃系挠氏?
* $password 你的邮箱密码
* $smtp 您的SMTP 服务器供应商,可以是域名或IP地址
* $check SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证
*/
function ZhozPhpSmtpSendMail ( $from, $password, $smtp, $check = 1 ) {
if( preg_match("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-zA-Z\d\-]+[^\-](\.[^\-][a-zA-Z\d\-]*[^\-])*\.[a-zA-Z]{2,3}/", $from ) ) {
$this->username = substr( $from, 0, strpos( $from , "@" ) );
$this->password = $password;
$this->smtp = $smtp ? $smtp : $this->smtp;
$this->check = $check;
$this->s_from = $from;
}
}
/*
* 功能:发送邮件
* $to 目标邮箱
* $from 来源邮箱
* $subject 邮件标题
* $message 邮件内容
*/
function zhoz_send ($to, $from, $subject, $message) {
//连接服务器
$fp = fsockopen ( $this->smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息1:$lastmessage".__LINE__;
//HELO
$yourname = "YOURNAME";
if($this->check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息2:$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (emptyempty($lastmessage)) )
break;
}
//身份验证
if ($this->check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息3:$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($this->username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息4:$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($this->password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息5:$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: <". $this->s_from . ">\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息6:$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: <". $to ."> \r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息7:$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息8:$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: $from\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fclose($fp);
error_log("send over------->ok!!", 0);
return true;
}
}
?>
<?php
/*
* php smtp发送邮件Scoket类
* ZhozPhpSmtpSendMail.php
* Created on 2008/09/02 zhoz.com
* @author zhoz
* v 1.72 update 2008/09/26 zhoz.Com
*/
class ZhozPhpSmtpSendMail {
//您的SMTP 服务器供应商,可以是域名或IP地址
var $smtp = "";
//SMTP需要要身份验证设值为 1, 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系。
var $check = 1;
//您的email帐号名称
var $username = "";
//您的email密码
var $password = "";
//此email 必需是发信服务器上的email
var $s_from = "";
/*
* 功能:发信初始化设置
* $from 你的发信服务器上的邮箱
* $password 你的邮箱密码
* $smtp 您的SMTP 服务器供应商,可以是域名或IP地址
* $check SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证
*/
function ZhozPhpSmtpSendMail ( $from, $password, $smtp, $check = 1 ) {
if( preg_match("/^[^\d\-_][\w\-]*[^\-_]@[^\-][a-zA-Z\d\-]+[^\-](\.[^\-][a-zA-Z\d\-]*[^\-])*\.[a-zA-Z]{2,3}/", $from ) ) {
$this->username = substr( $from, 0, strpos( $from , "@" ) );
$this->password = $password;
$this->smtp = $smtp ? $smtp : $this->smtp;
$this->check = $check;
$this->s_from = $from;
}
}
/*
* 功能:发送邮件
* $to 目标邮箱
* $from 来源邮箱
* $subject 邮件标题
* $message 邮件内容
*/
function zhoz_send ($to, $from, $subject, $message) {
//连接服务器
$fp = fsockopen ( $this->smtp, 25, $errno, $errstr, 60);
if (!$fp ) return "联接服务器失败".__LINE__;
set_socket_blocking($fp, true );
$lastmessage=fgets($fp,512);
if ( substr($lastmessage,0,3) != 220 ) return "错误信息1:$lastmessage".__LINE__;
//HELO
$yourname = "YOURNAME";
if($this->check == "1") $lastact="EHLO ".$yourname."\r\n";
else $lastact="HELO ".$yourname."\r\n";
fputs($fp, $lastact);
$lastmessage == fgets($fp,512);
if (substr($lastmessage,0,3) != 220 ) return "错误信息2:$lastmessage".__LINE__;
while (true) {
$lastmessage = fgets($fp,512);
if ( (substr($lastmessage,3,1) != "-") or (empty($lastmessage)) )
break;
}
//身份验证
if ($this->check=="1") {
//验证开始
$lastact="AUTH LOGIN"."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息3:$lastmessage".__LINE__;
//用户姓名
$lastact=base64_encode($this->username)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 334) return "错误信息4:$lastmessage".__LINE__;
//用户密码
$lastact=base64_encode($this->password)."\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != "235") return "错误信息5:$lastmessage".__LINE__;
}
//FROM:
$lastact="MAIL FROM: <". $this->s_from . ">\r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息6:$lastmessage".__LINE__;
//TO:
$lastact="RCPT TO: <". $to ."> \r\n";
fputs( $fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 250) return "错误信息7:$lastmessage".__LINE__;
//DATA
$lastact="DATA\r\n";
fputs($fp, $lastact);
$lastmessage = fgets ($fp,512);
if (substr($lastmessage,0,3) != 354) return "错误信息8:$lastmessage".__LINE__;
//处理Subject头
$head="Subject: $subject\r\n";
$message = $head."\r\n".$message;
//处理From头
$head="From: $from\r\n";
$message = $head.$message;
//处理To头
$head="To: $to\r\n";
$message = $head.$message;
//加上结束串
$message .= "\r\n.\r\n";
//发送信息
fputs($fp, $message);
$lastact="QUIT\r\n";
fclose($fp);
error_log("send over------->ok!!", 0);
return true;
}
}
?>
测试方法一样。上一个:Discuz 模板语句分析及知识技巧
下一个:php 分页原理详解
- 更多php疑问解答:
- php使用imagick将image图片转化为字符串模式
- php通过gd实现图片图片转换为字符图代码
- PHP把图片转base64代码,php把base64代码转换为图片并保存
- PHP把图片base64转换成图片并保存成文件
- wordpress问题<?php if(have_posts()) : ?>
- 建设一个搜索类网站php还是jsp,数据库那个好
- 没理由啊 php代码无法执行,貌似有语法错误。。。
- 关于PHP 和API 的一段代码不懂啊不懂,请高手指点! 这是淘宝API的
- php语言中,序列化到底在那里使用?它的优势是什么?劣势是什么?
- PHP函数等于或等于应该怎么表达
- 请教php高手,解决basename函数和mb_substr函数处理中文文件名称的解决方法,在上传文件时,总是出现乱码
- .NET,PHP,JAVA,JS优秀点分别是?
- 织梦cms 在环境监测的时候 wamp5 gd不支持 是为什么。;extension=php_gd2.dll这一句我删除了还是不显示?
- 我想学PHP。1.应安装什么编程工具? 2. 装LIUNX系统是装简易的还是?什么版本的?3.还应安装什么?
- <?php 和 <? 有什么区别