Home >php教程 >php手册 >PHP利用Jmail组件实现发送邮件

PHP利用Jmail组件实现发送邮件

WBOY
WBOYOriginal
2016-05-25 16:49:131380browse

学过asp的朋友可能知道jmail组件是使用在asp中一个常用的邮箱发送功能,在php中如果想调用jmail功能我们需要使用com组件来操作,我们先来介绍格式,代码如下:

$Jmail = new com("Jmail.Message"); //实例化一个Jmail对象 
$Jmail->SiLent=true; //设置成True的话Jmail不会提示错误只会返回True和False 
$Jmail->LogGing = false; //是否开启日志 
$Jmail->CharSet = "UTF8"; //设定字符串编码 
$Jmail->ContentType = "Text/html"; //邮件的格式为HTML格式 
$Jmail->MailServerUsername = '发信邮箱用户名'; 
$Jmail->MailServerPassword = '发信邮箱密码'; 
$Jmail->MailServerAddress='Smtp服务器的地址' 
$Jmail->FromName = '发件人姓名'; 
$Jmail->From = '发件人地址';  
$Jmail->AddRecipient('收件人地址');  
$html='Email正文'; 
$Jmail->Subject = 'Email标题'; 
$Jmail->Body = $html; 
$JmailError = $Jmail->Send($Jmail->MailServerAddress);  
if($JmailError){ echo '发送成功'; }

实例代码如下:

<?php   
$jmail = new COM(&#39;JMail.Message&#39;)   o&#114; die(&#39;无法调用Jmail组件&#39;);   
$jmail->silent = true; //屏蔽例外错误   
$jmail->charset = &#39;gb2312&#39;; //否则中文会乱码   
$jmail->From = &#39;web535000@163.com&#39;; //这里理论上是可以不与发件人地址相同的,但用163的试了几次都不行,改成一样的就可以了   
$jmail->FromName = &#39;BoboTest&#39;;   
$jmail->AddRecipient(&#39;abc1@163.com&#39;); //可添加多个邮件接受者   
//$jmail->AddRecipient(&#39;abc2@163.com&#39;);   
//$jmail->AddRecipient(&#39;abc3@163.com&#39;);   
$jmail->Subject = &#39;email test.&#39;;   
$jmail->Body = &#39;this is test email.&#39;;    
$jmail->MailServerUserName = &#39;web535000@163.com&#39;; //发信邮件账号   
$jmail->MailServerPassword = &#39;123456&#39;; //账户的密码   
try{   
$email = $jmail->Send(&#39;smtp.163.com&#39;);   
if($email) echo &#39;发送成功&#39;;   
else echo &#39;发送失败&#39;;   
} catch (Exception $e){   
echo $e->getMessage();   
}   
?>


文章地址:

转载随意^^请带上本文地址!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn