学过asp的朋友可能知道jmail组件是使用在asp中一个常用的邮箱发送功能,在php中如果想调用jmail功能我们需要使用com组件来操作,我们先来介绍格式,代码如下:
- $Jmail = new com("Jmail.Message");
- $Jmail->SiLent=true;
- $Jmail->LogGing = false;
- $Jmail->CharSet = "UTF8";
- $Jmail->ContentType = "Text/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('JMail.Message') or die('无法调用Jmail组件');
- $jmail->silent = true;
- $jmail->charset = 'gb2312';
- $jmail->From = 'web535000@163.com';
- 成一样的就可以了
- $jmail->FromName = 'BoboTest';
- $jmail->AddRecipient('abc1@163.com');
-
-
- $jmail->Subject = 'email test.';
- $jmail->Body = 'this is test email.';
- $jmail->MailServerUserName = 'web535000@163.com';
- $jmail->MailServerPassword = '123456';
- try{
- $email = $jmail->Send('smtp.163.com');
- if($email) echo '发送成功';
- else echo '发送失败';
- } catch (Exception $e){
- echo $e->getMessage();
- }
- ?>
|