PHP邮件发送的程序 SMTP验证
来源:互联网 发布:c 网络编程 多线程 编辑:程序博客网 时间:2024/04/29 01:21
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 ");
}
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 ");
$this->elog(fgets($this->connection, 1024));
$base64_username=base64_encode($this->username);
$this->elog("$base64_username", 1);
fputs($this->connection,"$base64_username ");
$this->elog(fgets($this->connection, 1024));
$base64_password=base64_encode($this->password);
$this->elog("$base64_password", 1);
fputs($this->connection,"$base64_password ");
$this->elog(fgets($this->connection, 1024));
}
$this->elog("MAIL FROM:$from_mail", 1);
fputs($this->connection,"MAIL FROM:$from_mail ");
$this->elog(fgets($this->connection, 1024));
$this->elog("RCPT TO:$to_mail", 1);
fputs($this->connection, "RCPT TO:$to_mail ");
$this->elog(fgets($this->connection, 1024));
$this->elog("DATA", 1);
fputs($this->connection, "DATA ");
$this->elog(fgets($this->connection, 1024));
$this->elog("Subject: $subject", 1);
$this->elog("To: $to_name", 1);
fputs($this->connection,"Subject: $subject ");
fputs($this->connection,"To: $to_name ");
if ($header)
{
$this->elog($header, 1);
fputs($this->connection, "$header ");
}
$this->elog("", 1);
$this->elog($body, 1);
$this->elog(".", 1);
fputs($this->connection,"");
fputs($this->connection,"$body");
fputs($this->connection,".");
$this->elog(fgets($this->connection, 1024));
return 1;
}
function send()
{
if ($this->connection)
{
fputs($this->connection, "QUIT
");
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, "
-------------------------------------------
");
fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "
");
fwrite($this->elog_fp, "-------------------------------------------
");
}
// write to log
if (!$mode)
{
fwrite($this->elog_fp, " $text
");
}
else
{
fwrite($this->elog_fp, "$text
");
}
}
}
?>
c_mail.php
CODE:
<?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;/n ";
$headers .= "Content-type: text/html; charset=gb2312 ;/n";
$headers .= "From: ".$from_name."<".$from_mail.">;/n ";
$headers .= "To: ".$to_name."<".$to_mail.">;/n ";
$headers .= "X-Priority: 1 ;/n";
$headers .= "X-MSMail-Priority: High ;/n";
// 开始发送邮件
if($smtp_server['name']=='')
{
if(@mail($to_mail, $subject,$message, $headers)){
echo "<br><br><center>邮件已经成功发送!请查收</center>";
echo "<br><br><center><a href='#' onclick='javascript:window.close()'>关闭窗口</a></center>";
}
else{
}
}
else{}
}
}
?>
config.php
CODE:
$smtp_server['name'] =''; //smtp服务器地址,如:smtp.163.com
$smtp_server['need_auth'] =true;//smtp服务器是否需要验证
$smtp_server['username'] ='';//smtp服务器用户名,即邮箱名称
$smtp_server['password'] ='';//smtp服务器密码,即邮箱密码
sendmail.php
CODE:
<?
ob_start();
@include_once("config.php");
@require_once "c_mail.php";
//调用
$c_mail = new c_mail();
$c_mail->html_mailer($yourname,$from,$to,$to,$subject,$content,$reply_mail);
ob_end_flush();
?>
- PHP邮件发送的程序 SMTP验证
- PHP如何通过SMTP验证发送邮件
- php SMTP发送邮件
- php smtp发送邮件
- php发送smtp邮件
- php邮件发送SMTP
- php SMTP 发送 邮件
- PHP模拟SMTP发送邮件的类
- PHP实现的SMTP发送邮件
- PHP+SMTP的邮件发送机制
- 基于SMTP的JAVA邮件发送程序
- 基于SMTP的JAVA邮件发送程序!
- c#发送smtp验证邮件
- SMTP邮件的发送
- 关于PHP 发送SMTP邮件 的邮件类phpmailer 参数
- php通过smtp发送邮件
- 用php发送邮件SMTP
- php smtp邮件发送代码
- 外围防火墙规则+内部防火墙规则
- 小心啦,小心你的主板也要被烧
- 今天我想要重生
- UML辅助网站规划和设计指南
- 先开个头
- PHP邮件发送的程序 SMTP验证
- 编程修养(上)
- 编程修养(中)
- 编程修养(下)
- google的错?ie的错?还是iframe的错?
- 程序版吉祥三宝
- oracle连接数据库
- ★ Eclipse 3.0 RC2 热键表 (中英对照解说版,Default) ★
- 求助?想要一些源程序?可以帮帮我吗?