php+Mashup Service实现邮件正文和附件发送Cognos报表数据(1)——php上的邮件配置

浏览: 2544

由于Cognos发送邮件功能的限制,无法同时在正文和附件中发送不同格式的报表数据,特采用php+Mashup Service的方式来变通实现。本文是实现笔记。

 

首先尝试在php上实现邮件发送。

利用开源的php类PHPMailer实现发送功能,通过https://github.com/Synchro/PHPMailer下载。下载解压放到htdocs目录下。

 

在编写php代码时参考以下代码:

<?php
require_once(“PHPMailer/PHPMailerAutoload.php”);
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ‘smtp.163.com’; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘cognosplus@163.com’; // SMTP username
$mail->Password = ‘Password’; // SMTP password
//$mail->SMTPSecure = ‘tls’; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->CharSet = “gbk”; // 这里指定字符集!
$mail->Encoding = “base64″;
$mail->From = ‘cognosplus@163.com’;
$mail->FromName = ‘CognosPlus’;
$mail->addAddress(‘hupingzhi@163.com’, ‘Hupz’); // Add a recipient
//$mail->addAddress(‘ellen@example.com’); // Name is optional
//$mail->addReplyTo(‘info@example.com’, ‘Information’);
//$mail->addCC(‘cc@example.com’);
//$mail->addBCC(‘bcc@example.com’);
//$mail->addAttachment(‘/var/tmp/file.tar.gz’); // Add attachments
//$mail->addAttachment(‘/tmp/image.jpg’, ‘new.jpg’); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = ‘Here is the subject’;
$mail->Body = ‘
<html><head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gbk”>
</head>
<body>
看看能否显示中文?
</body>
</html>
‘;
$mail->AltBody = ‘This is the body in plain text for non-HTML mail clients’;
date_default_timezone_set(“Asia/Shanghai”);
if(!$mail->send()) {
echo ‘Message could not be sent.’;
echo ‘Mailer Error: ‘ . $mail->ErrorInfo;
} else {
echo ‘Message has been sent’.date(“Y-m-d H:i:s”);
}
?>

运行测试结果,可以正常发送。

推荐 0
本文由 hupingzhi 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册