c_smtp_client.php
<?php
/* smtp client class */
class c_smtp_client
{
var $connection;
var $server;
var $elog_fp;
var $log_file='./smtp_client.log';
var $do_log=true;
var $need_auth=true;
var $username;
var $password;
// 构造器
function c_smtp_client($server='')
{
if (!$server)
{
$this->server="localhost";
}
else
{
$this->server=$server;
}
$this->connection = fsockopen($this->server, 25);
if ($this->connection <= 0) return 0;
fputs($this->connection,"HELO xyz/r/n");
}
function email($from_mail, $to_mail, $to_name, $header, $subject, $body)
{
if ($this->connection <= 0) return 0;
// 邮件用户认证
if ($this->need_auth)
{
$this->elog("AUTH LOGIN", 1);
fputs($this->connection,"AUTH LOGIN/r/n");
$this->elog(fgets($this->connection, 1024));
$base64_username=base64_encode($this->username);
$this->elog("$base64_username", 1);
fputs($this->connection,"$base64_username/r/n");
$this->elog(fgets($this->connection, 1024));
$base64_password=base64_encode($this->password);
$this->elog("$base64_password", 1);
fputs($this->connection,"$base64_password/r/n");
$this->elog(fgets($this->connection, 1024));
}
$this->elog("MAIL FROM:$from_mail", 1);
fputs($this->connection,"MAIL FROM:$from_mail/r/n");
$this->elog(fgets($this->connection, 1024));
$this->elog("RCPT TO:$to_mail", 1);
fputs($this->connection, "RCPT TO:$to_mail/r/n");
$this->elog(fgets($this->connection, 1024));
$this->elog("DATA", 1);
fputs($this->connection, "DATA/r/n");
$this->elog(fgets($this->connection, 1024));
$this->elog("Subject: $subject", 1);
$this->elog("To: $to_name", 1);
fputs($this->connection,"Subject: $subject/r/n");
fputs($this->connection,"To: $to_name/r/n");
if ($header)
{
$this->elog($header, 1);
fputs($this->connection, "$header/r/n");
}
$this->elog("", 1);
$this->elog($body, 1);
$this->elog(".", 1);
fputs($this->connection,"/r/n");
fputs($this->connection,"$body /r/n");
fputs($this->connection,"./r/n");
$this->elog(fgets($this->connection, 1024));
return 1;
}
function send()
{
if ($this->connection)
{
fputs($this->connection, "QUIT/r/n");
fclose($this->connection);
$this->connection=0;
}
}
function close()
{
$this->send();
}
function elog($text, $mode=0)
{
if (!$this->do_log) return;
// open file
if (!$this->elog_fp)
{
if (!($this->elog_fp=fopen($this->log_file, 'a'))) return;
fwrite($this->elog_fp, "/n-------------------------------------------/n");
fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "/n");
fwrite($this->elog_fp, "-------------------------------------------/n");
}
// write to log
if (!$mode)
{
fwrite($this->elog_fp, "$text/n");
}
else
{
fwrite($this->elog_fp, "$text/n");
}
}
}
?>
c_mail.php
<?php
/* 邮件发送类 */
require_once dirname(__FILE__)."/c_smtp_client.php";
static $c_smtp_client;
if(!isset($c_smtp_client))
{
$c_smtp_client=& new c_smtp_client($smtp_server['name']);
$c_smtp_client->do_log=false;
$c_smtp_client->need_auth=$smtp_server['need_auth'];
$c_smtp_client->username=$smtp_server['username'];
$c_smtp_client->password=$smtp_server['password'];
}
class c_mail
{
// html格式的Mail信笺
function html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail)
{
$headers="";
$headers.="MIME-Version: 1.0/r/n";
$headers.="Content-type: text/html; charset=gb2312/r/n";
$headers.="From: ".$from_name."<".$from_mail.">/r/n";
$headers.="To: ".$to_name."<".$to_mail.">/r/n";
$headers.="Reply-To: ".$from_name."<".$reply_mail.">/r/n";
$headers.="X-Priority: 1/r/n";
$headers.="X-MSMail-Priority: High/r/n";
$headers.="X-Mailer: WebCMS MAIL SERV";
// 开始发送邮件
if($smtp_server['name']=='')
{
@mail($to_mail, $subject, $message, $headers);
}
else
{
$c_smtp_client->email($from_mail,$to_mail,$to_name,$headers,$subject,$message);
$c_smtp_client->send();
}
}
}
?>
config.inc.php
<?php
//smtp_server['name']=='';则表示直接使用mail();
//smtp_server['name']=='localhost';表示程序所在主机的smtp服务器
$smtp_server['name']="";
$smtp_server['need_auth']=true;
$smtp_server['username']='';
$smtp_server['password']='';
?>
sendmail.php
<?php
//调用方法
require_once dirname(__FILE__)."/config.inc.php";
require_once dirname(__FILE__)."/c_mail.php";
$c_mail= new c_mail();
$c_mail->html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail);
?>
分享到:
相关推荐
使用stmp服务发送邮件,可用于app自动返回错误信息
使用c#实现stmp发送邮件的简单例子!自己建立一个窗体,将发送事件中的代码复制即可实现简单的邮件发送例子!
python调用内置的stmp模块发送邮件,带附件发送
一个支持IMAP、STMP、POP3的邮件库,可以在VC下使用!安装包里有程序库、例子和使用手册。
C# 的stmp邮件发送测试
stmp与pop功能,实现邮件的发送与拉取
php发送邮件工具,php发送邮件工具,php发送邮件工具,php发送邮件工具
这是河北联合大学TCP/IP课程设计的基于pop3和stmp邮件收发系统的代码和报告,java代码开发,绝对可用!
Android调用谷歌STMP发送邮件,手机端利用stmp发送邮件至邮箱
分享一个PHP邮件STMP简单类,这里使用了163的邮箱,SMTP服务器,连接端口,SMTP服务器的用户邮箱,需要服务器账号和密码,提示是否使用身份验证,是否显示发送的调试信息。
一个简单的vs 2015 MFC项目,支持多用户,可以显示客户端发送邮件的内容,给出了协议的交互日志,暂未实现转发功能。 项目中的readme.txt附带了一点点协议,base64的介绍
基于STMP与POP3协议的邮件发送与接收.pdf基于STMP与POP3协议的邮件发送与接收.pdf基于STMP与POP3协议的邮件发送与接收.pdf基于STMP与POP3协议的邮件发送与接收.pdf基于STMP与POP3协议的邮件发送与接收.pdf基于STMP与...
c++使用stmp协议发送邮件(163的邮箱,TTL非SSL) 快速链接到我的blog文: http://blog.csdn.net/zengraoli/article/details/36866241
mp3-4 STMP3410原理图 mp3-4 STMP3410原理图 mp3-4 STMP3410原理图
stmp3520资料
STMP3502资料
实现邮件告警,直接make一下,C语言stmp 使用方法如下:。./mail -s [标题] -f [发件人地址] -r [回复的邮件地址] -S [邮件服务器地址]-T [发送的字符串] -F [发送的文件名的内容] 收件人地址
Android高级应用源码-Android调用谷歌STMP发送邮件 MailDemo.zip
主要为大家详细介绍了Java Web stmp发送带附件邮件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下