详细讲解PHP的Jmai组件及发送邮件实例_MAIL邮件服务器_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

详细讲解PHP的Jmai组件及发送邮件实例

作者:黑客防线网安Mail教程网 来源:黑客防线网安Mail教程网 浏览次数:0

本篇关键词:发送邮件实例组件
黑客防线网安网讯:<%On error resume nextDim JMail, contentIdSet JMail = Server.CreateObject("JMail.Meage")JMail.Charset = "gb2312" ' 邮件字符集,默认为"US-ASCII"' JMail.ISOEncodeHeaders = False ...
<%
On error resume next
Dim JMail, contentId
Set JMail = Server.CreateObject("JMail.Meage")
JMail.Charset = "gb2312" ' 邮件字符集默认为"US-ASCII"
' JMail.ISOEncodeHeaders = False ' 是否进行ISO编码默认为True
' 发送者信息(可用变量方式赋值)
JMail.From = "webjxcom@163.com" ' 发送者地址
JMail.FromName = "网站管理员" ' 发送者姓名
JMail.Subject = "邮件主题" ' 邮件主题
' 身份验证
JMail.MailServerUserName = "webjx" ' 身份验证的用户名
JMail.MailServerPaword = "webjx" ' 身份验证的密码
' 设置优先级,范围从1到5,越大的优先级越高,3为普通
JMail.Priority = 1
JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
' 加入一个收件人【变量email:收件人地址】可以同一语句重复加入多个
JMail.AddRecipient("5@163.com")
' 加入附件【变量filename:附件文件的绝对地址,确保用户IUSR_机器名有访问的权限】
' 【参数设置是(True)否(False)为Inline方式】
'contentId = JMail.AddAttachment (Server.Maath("jmail.a"), True)
' 邮件主体(HTML(注意信件内链接附件的方式))
'JMail.AendBodyFromFile(Server.Maath("/Love/Inc/Mailend.txt"))
JMail.HTMLBody = "<html>lt;head>lt;META content=zh-cn http-equiv=Content-Language>lt;meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">lttyle type=text/cgt;A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}ODY {FONT-SIZE: 9pt} -->lt;/style>lt;/head>ltody>lt;font color=red>邮件正文</font>ltr>lt;font color=greegt;邮件正文</font>ltr>ltgt;邮件正文</gtlt;/body>lt;/html>"
' 邮件主体(文本部分)
JMail.Body = "我们的邮件采用了HTML格式,但是您的邮件查看软件可能不支持。邮件正文,邮件正文,邮件正文"
' 发送【调用格式:objJMail.Send([username:paword@]SMTerverAddre[:Port])】
JMail.Send("smtp.163.com")
' 关闭并清除对象
JMail.Close()
Set JMail = Nothing
if err.number<gt;0 then
reoe.write "发送发送失败!"
else
reoe.write "邮件发送成功!"
end if
%> <?php
cla smtp
{
/* Public Variables */
var $mtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $a
/* Private Variables */
var $ock;
/* Cotractor */
function smtp($relay_host = "", $mtp_port = 25,$auth = false,$user,$a)
{
$this->debug = FALSE;
$this->mtp_port = $mtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->a = $a
#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file = "";
$this->ock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $ubject = "", $ody = "", $mailtype, $cc = "", $cc = "", $additional_headers = "")
{
$mail_from = $this->get_addre($this->trip_comment($from));
$ody = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $ody);
$header = "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "T ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$ubject."\r\n";
$header .= $additional_header
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $ec) = explode(" ", microtime());
$header .= "Meage-ID: <".date("YmdHis", $ec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->trip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->trip_comment($cc)));
}
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->trip_comment($cc)));
}
$ent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_addre($rcpt_to);
if (!$this->mtp_sockopen($rcpt_to)) {
$this->log_write("Error: Caot send email to ".$rcpt_to."\n");
$ent = FALSE;
continue;
}
if ($this->mtp_send($this->host_name, $mail_from, $rcpt_to, $header, $ody)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else {
$this->log_write("Error: Caot send email to <".$rcpt_to.">\n");
$ent = FALSE;
}
fclose($this->ock);
$this->log_write("Discoected from remote host\n");
}
return $ent;
}
/* Private Functio */
function smtp_send($helo, $from, $to, $header, $ody = "")
{
if (!$this->mtp_putcmd("HELO", $helo)) {
return $this->mtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->mtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->mtp_error("sending HELO command");
}
if (!$this->mtp_putcmd("", base64_encode($this->a))) {
return $this->mtp_error("sending HELO command");
}
}
#
if (!$this->mtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->mtp_error("sending MAIL FROM command");
}
if (!$this->mtp_putcmd("RCPT", "T<".$to.">")) {
return $this->mtp_error("sending RCPT TO command");
}
if (!$this->mtp_putcmd("DATA")) {
return $this->mtp_error("sending DATA command");
}
if (!$this->mtp_meage($header, $ody)) {
return $this->mtp_error("sending meage");
}
if (!$this->mtp_eom()) {
return $this->mtp_error("sending <CR>lt;LF>.<CR>lt;LF> [EOM]");
}
if (!$this->mtp_putcmd("QUIT")) {
return $this->mtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($addre)
{
if ($this->relay_host == "") {
return $this->mtp_sockopen_mx($addre);
} else {
return $this->mtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->mtp_port."\n");
$this->ock = @fsockopen($this->relay_host, $this->mtp_port, $errno, $errstr, $this->time_out);
if (!($this->ock &amam $this->mtp_ok())) {
$this->log_write("Error: Caot coenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Coected to relay host ".$this->relay_host."\n");
return TRUE;
}
function smtp_sockopen_mx($addre)
{
$domain = ereg_replace("^.+@([^@]+)$", "\1", $addre);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Caot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->mtp_port."\n");
$this->ock = @fsockopen($host, $this->mtp_port, $errno, $errstr, $this->time_out);
if (!($this->ock &amam $this->mtp_ok())) {
$this->log_write("Warning: Caot coect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Coected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Caot coect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_meage($header, $ody)
{
fputs($this->ock, $header."\r\n".$ody);
$this->mtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\gt; ".$ody."\gt; "));
return TRUE;
}
function smtp_eom()
{
fputs($this->ock, "\r\n.\r\n");
$this->mtp_debug(". [EOM]\n");
return $this->mtp_ok();
}
function smtp_ok()
{
$reoe = str_replace("\r\n", "", fgets($this->ock, 512));
$this->mtp_debug($reoe."\n");
if (!ereg("^[23]", $reoe)) {
fputs($this->ock, "QUIT\r\n");
fgets($this->ock, 512);
$this->log_write("Error: Remote host returned \"".$reoe."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->ock, $cmd."\r\n");
$this->mtp_debug("> ".$cmd."\n");
return $this->mtp_ok();
}
function smtp_error($tring)
{
$this->log_write("Error: Error occurred while ".$tring.".\n");
return FALSE;
}
function log_write($meage)
{
$this->mtp_debug($meage);
if ($this->log_file == "") {
return TRUE;
}
$meage = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$meage;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->mtp_debug("Warning: Caot open log file \"".$this->log_file."\"\n");
return FALSE
}
flock($fp, LOCK_EX);
fputs($fp, $meage);
fclose($fp);
return TRUE;
}
function strip_comment($addre)
{
$comment = "\([^()]*\)";
while (ereg($comment, $addre)) {
$addre = ereg_replace($comment, "", $addre);
}
return $addre
}
function get_addre($addre)
{
$addre = ereg_replace("([ \t\r\n])+", "", $addre);
$addre = ereg_replace("^.*<(.+)>.*$", "\1", $addre);
return $addre
}
function smtp_debug($meage)
{
if ($this->debug) {
echo $meage;
}
}
}
?> //*****************************************************************
// *.php 使用文件,看清楚了,怎么使用在这里
//
//*****************************************************************
<?php
//require (FILE_DIR."smtp.php");
$mterver = "smtp.163.com";//SMTP服务器
$mterverport =25;//SMTP服务器端口
$mtpusermail = "webjx@163.com";//SMTP服务器的用户邮箱
$mtpemailto = "webjx@163.com";//发送给谁
$mtpuser = "webjx";//SMTP服务器的用户帐号
$mta = "webjx";//SMTP服务器的用户密码
$mailsubject = "Test Subject";//邮件主题
$mailbody = "<h1>This is a test mail</h1>";//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
$mtp = new smtp($mterver,$mterverport,true,$mtpuser,$mta);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$mtp->debug = TRUE;//是否显示发送的调试信息
$mtp->endmail($mtpemailto, $mtpusermail, $mailsubject, $mailbody, $mailtype);
?>
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-19353-1.html
网站维护教程更新时间:2012-12-17 02:12:16  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer