PHP调用Jmail组件发邮件代码

精贴 置顶
2362 0

<meta http-equiv=’Content-Type’ content=’text/html; charset=gb2312′>
<?php

/*

名称:邮件发送类!!!

功能:使用SMTP服务器,在PHP代码中发送邮件。

特点:可以使用要求身份验证的SMTP服务器。

使用方法: 请参照示例文件:SendEmail_Example.php

*/

class smtp

{

/* Public Variables */

var $smtp_port;

var $time_out;

var $host_name;

var $log_file;

var $relay_host;

var $debug;

var $auth;

var $user;

var $pass;

/* Private Variables */
var $sock;

/* Constractor */

function smtp($relay_host = “”, $smtp_port = 25,$auth = false,$user,$pass)

{

$this->debug = FALSE;

$this->smtp_port = $smtp_port;

$this->relay_host = $relay_host;

$this->time_out = 30; //is used in fsockopen()
#

$this->auth = $auth;//auth

$this->user = $user;

$this->pass = $pass;

#

$this->host_name = “localhost”; //is used in HELO command
$this->log_file = “”;
$this->sock = FALSE;

}

/* Main Function */

function sendmail($to, $from, $subject = “”, $body = “”, $mailtype, $cc = “”, $bcc = “”, $additional_headers = “”)

{

$mail_from = $this->get_address($this->strip_comment($from));

$body = ereg_replace(“(^|(\r\n))(\.)”, “\1.\3″, $body);
$header=”";
$header .= “MIME-Version:1.0\r\n”;

if($mailtype==”HTML”){

$header .= “Content-Type:text/html\r\n”;

}

$header .= “To: “.$to.”\r\n”;

if ($cc != “”) {

$header .= “Cc: “.$cc.”\r\n”;

}

$header .= “From: $from<”.$from.”>\r\n”;

$header .= “Subject: “.$subject.”\r\n”;

$header .= $additional_headers;

$header .= “Date: “.date(“r”).”\r\n”;

$header .= “X-Mailer:By Redhat (PHP/”.phpversion().”)\r\n”;

list($msec, $sec) = explode(” “, microtime());

$header .= “Message-ID: <”.date(“YmdHis”, $sec).”.”.($msec*1000000).”.”.$mail_from.”>\r\n”;

$TO = explode(“,”, $this->strip_comment($to));

if ($cc != “”) {

$TO = array_merge($TO, explode(“,”, $this->strip_comment($cc)));

}

if ($bcc != “”) {

$TO = array_merge($TO, explode(“,”, $this->strip_comment($bcc)));

}

$sent = TRUE;

foreach ($TO as $rcpt_to) {

$rcpt_to = $this->get_address($rcpt_to);

if (!$this->smtp_sockopen($rcpt_to)) {

$this->log_write(“Error: Cannot send email to “.$rcpt_to.”\n”);

$sent = FALSE;

continue;

}

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {

$this->log_write(“E-mail has been sent to <”.$rcpt_to.”>\n”);

} else {

$this->log_write(“Error: Cannot send email to <”.$rcpt_to.”>\n”);

$sent = FALSE;

}

fclose($this->sock);

$this->log_write(“Disconnected from remote host\n”);

}

return $sent;

}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = “”)

{

if (!$this->smtp_putcmd(“HELO”, $helo)) {

return $this->smtp_error(“sending HELO command”);

}

#auth

  • 没有任何评论
今日天气 ···

···

···

···

热门排行
CSS cursor鼠标样式一览表 2012/6/25
.NET后台写JS代码 2011/11/3
网站地址多出jdfwkey的问题解析及... 2010/8/25
百度、google、Yahoo网站地图制作... 2011/1/30
数据库xxx的日志已满,请备份该数... 2013/7/19
<a>标签的伪类书写顺序问题... 2010/9/4
CEO名言 2010/8/31
什么是长尾关键词? 2010/9/24
Mysql 主从数据库同步 2010/9/12
用ASP实现网页BBS 2010/11/1
博主推荐
网站title标题如何正确修改不会被... 2013/8/26
ASP .NET MYSQL 的简单分页 并不... 2013/8/19
网站有弹窗广告这样的站点,百度... 2013/8/17
做淘宝SEO优化需要注意的8大问题 2013/8/17
淘宝网怎么做SEO优化 2013/8/17
站长们要学习的“苍井空精神” 2013/8/17
苹果公司今日发布了iOS 7第五个开... 2013/8/7
小米1刷V5系统WIFI不能连接解决办... 2013/8/1
本博客手机版上线咯!会员后台也... 2013/7/31
Win7系统环境安装配置PHP开发环境... 2013/7/29
随便看看
服务器安全:防范拒绝服务攻击妙... 2010/9/6
使用CSS设置网页图片透明度 2013/11/9
JAVA定时执行任务的三种方法 2013/6/24
Alexa排名是什么? 2010/9/14
常用正则表达式大全 2010/8/27
.net将IP转换为10进制 2013/7/18
Java趣味编程:经典的农夫养牛问... 2013/6/21
怎样设置域名泛解析 2013/10/21
在ASP中使用Oracle数据库 2010/10/19
seo自身对于网站降权的处理 2013/6/23
北京 上海 杭州 深圳 广州 成都