php中socket方式发送邮件代码示例
来源:互联网 发布:养成类游戏源码 编辑:程序博客网 时间:2024/05/17 00:52
/**
* FileName: sendMail.fun.php
* Author: interlover0@gmail.com
* Description:
* 邮件发送函数定义文件,源引自作者的SendMail类,该函数是使用socket进行邮件发送的,仅支持文本
*/
/**
* 纯文本邮件发送函数
*
* @param string $_str_title
* @param string $_str_content
* @param string $_str_toAddress
* @param string $_str_toUser
* @return boolean
*/
function sendMail( $_str_title , $_str_content , $_str_toAddress , $_str_toUser = null ){
$_str_thisPlace = "Function: sendMail >> ";
$_void_result = false;
if( empty( $_str_toUser ) )
$_str_toUser = $_str_toAddress;
$_obj_sendMail = new SendMail( $_str_toAddress , $_str_toUser , $_str_title );
$_obj_sendMail->setMailContent( $_str_content );
if( !$_obj_sendMail->send() )
return $_void_result;
//Return
$_void_result = true;
return $_void_result;
}
class SendMail
PHP5下的简单电子邮件发送类,用于发送文本信息。该类引用了php_sockets.dll库。
该类主要用于WEB站点发送系统信息到相关的用户。
该类模拟使用SOCKET连接AUTH LOGIN认证方式邮件服务器来进行邮件的发送工作。
---------------------------------------------
CopyRight interlover@163.com
2006.05.06
---------------------------------------------
class SendMail{
/**
* @desc Smtp Server Name or IP Address
* @var string
*/
private $popServer;
/**
* @desc Smtp Server Port Number
* @var int
*/
private $popServerPort;
/**
* @desc Email Sender Address
* @var string
*/
private $senderAddress;
/**
* @desc Smtp Server Login User Name
* @var string
*/
private $loginUser;
/**
* @desc Smtp Server Login User Password
* @var string
*/
private $password;
/**
* @desc Email Sender Name
* @var string
*/
private $fromUser;
/**
* @desc Send To Email Address
* @var string
*/
private $toMailAddress;
/**
* @desc Send To User Name
* @var string
*/
private $toUser;
/**
* @desc Email Title
* @var String
*/
private $mailTitle;
/**
* @desc Email Content
* @var string
*/
private $mailContent;
/**
* @desc Debug Set
* @var boolean
*/
private $debug = false;
/**
* @desc Error Information
* @var string
*/
private $error = null;
/**
* @desc Smtp Server Resouce
* @var string
*/
private $result;
/**
* @desc Socket Connect Handler
* @var handler
*/
private $socketConnect;
public function __construct( $getToMailAddress , $getToUser , $getMailTitle ){
$this->popServer = __ADMIN_EMAIL_HOST__;
$this->popServerPort = __ADMIN_EMAIL_HOST_PORT__;
$this->senderAddress = __ADMIN_EMAIL_ADDRESS__;
$this->loginUser = __ADMIN_EMAIL_ADDRESS__;
$this->password = __ADMIN_EMAIL_PASSWORD__;
$this->fromUser = __ADMIN_EMAIL_USER__;
$this->toMailAddress = $getToMailAddress;
$this->toUser = $getToUser;
$this->mailTitle = $getMailTitle;
}
public function __destruct(){
socket_close( $this->socketConnect );
}
/**
* @desc 创建到指定服务器地址的socket连接
*
* @return void
*/
private function createConnect(){
if( !$this->socketConnect = socket_create(AF_INET, SOCK_STREAM, SOL_TCP ) ){
echo "Exception: Socket Create Error!";
exit;
}//end if( !$this->socketConnect = socket_create(AF_INET, SOCK_STREAM, SOL_TCP ) )
if( !socket_connect( $this->socketConnect , $this->popServer , $this->popServerPort ) ){
echo "Exception: Socket Connect Error!";
exit;
}else{
$this->resouceCom();
}//end if( !socket_connect( $this->socketConnect , $this->popServer , $this->popServerPort ) )
}
/**
* @desc Socket命令序列。该方法更像一个属性。
*
* @return array
*/
private function comArray(){
$comArray = array(
"HELO EHLO\r\n" ,
"AUTH LOGIN\r\n" ,
base64_encode( $this->loginUser ) . "\r\n" ,
base64_encode( $this->password ) . "\r\n" ,
"MAIL FROM:<{$this->senderAddress}>\r\n" ,
"RCPT TO:<{$this->toMailAddress}>\r\n" ,
"DATA\r\n" ,
"TO:{$this->toUser}\r\n" .
"FROM:{$this->fromUser}\r\n" .
"SUBJECT:{$this->mailTitle}\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=\"UTF-8\"\r\n" .
$this->mailContent . "\r\n" .
".\r\n" ,
"QUIT\r\n"
);
return $comArray;
}
/**
* @desc 执行命令序列中的一条命令
*
* @param $setCom string
* @return boolean
*/
private function sendCom( $setCom ){
if( $this->debug ){
echo $setCom."<BR>";
}//end if( $this->debug )
socket_write( $this->socketConnect , $setCom , strlen( $setCom ) );
return $this->setError();
}
/**
* @desc 取得服务器的应答信息
*
* @return boolean
*/
private function resouceCom(){
$this->result = socket_read( $this->socketConnect , 1024 );
if( $this->debug ){
echo $this->result."<BR>";
}//end if( $this->debug )
return $this->setError( $this->result );
}
/**
* @desc 获取错误信息
*
* @param $checkString string
* @return boolean
*/
private function setError( $checkString = null ){
$this->error = null;
if( !empty( $checkString ) ){
if( ( $j = intval( substr( $checkString , 0 , 1 ) ) ) > 3 ){
$this->error = $checkString;
}//end if( intval( substr( $checkString , 0 , 1 ) ) > 3 )
}//end if( !empty( $checkString ) )
if( !empty( $this->error ) ){
if( $this->debug ){
echo "<span style = 'color:#ff0000;'>Error: ".$this->error."</span>";
}//end if( $this->debug )
return false;
}//end if( $this->debug )
return true;
}
/**
* @desc 设置是否显示调试信息
*
* @param $setDebug boolean
* @return void
*/
public function setDebug( $setDebug = false ){
$this->debug = $setDebug;
}
/**
* @desc 设置发送邮件的内容
*
* @param $setMailContent String
* @return void
*/
public function setMailContent( $setMailContent ){
$this->mailContent = $setMailContent;
}
/**
* @desc 获取发送的邮件的内容
*
* @return string
*/
public function getMail(){
if( $this->debug ){
$comArray = $this->comArray();
for( $i = 0 ; current( $comArray ) ; next( $comArray ) ){
echo $comArray[$i]."<BR>";
$i++;
}//end for( $i = 0 ; current( $comArray ) ; next( $comArray ) )
}//end if( $this->debug )
return $this->mailContent;
}
/**
* @desc 执行电子邮件的发送动作。
*
* @return void
*/
public function send(){
$this->createConnect();
$comArray = $this->comArray();
for( $i = 0 ; current( $comArray ) ; next($comArray) ){
if( !$this->sendCom( $comArray[$i] ) ){
return false;
}
if( !$this->resouceCom() ){
return false;
}
$i++;
}
return true;
}
}
- php中socket方式发送邮件代码示例
- php中socket邮件发送
- PHP发送邮件示例
- 邮件发送示例代码
- 邮件发送代码示例
- php 发送邮件代码
- socket方式发送邮件类
- PHP使用socket发送邮件
- 发送邮件的代码示例
- java发送邮件 示例代码
- php 邮件发送代码-php邮件群发
- php smtp邮件发送代码
- PHP邮件发送主要代码
- PHP邮件发送代码实现
- c#使用netmail方式发送邮件示例
- JAVA通过Socket方式发送邮件
- php通过socket,以SMTP发送邮件
- 简单SAP ABAP发送邮件示例代码
- 一些网站设计原型图 网页设计从纸上开始
- spring3与mybatis3的整合一例
- Win 旗舰版 IIS配制
- 酒店业与BlackBerry黑莓
- 用java SWT制作的一个模仿微软的计算器,1000行代码!
- php中socket方式发送邮件代码示例
- 基于postgreSQL9.1的中文全文检索(基于Linux)
- 顶部小图片鼠标经过效果:
- 编写高效Lua代码的方法 - 4 - 减少,重用,回收
- MessageFormat(动态文本)
- hibernate.cfg.xml配置总结(数据库连接池) .
- 出现/bin/sh: can't access tty; job control turned off的解决方案
- MCS-51单片机的存储器组织结构
- MySpaceV1.02 测试版发布