需要的php扩展:sockets、Fileinfo和openssl
在tp系统文件下的Extend->Vendor->Zend下放置phpmailer文件包,并把phpmailer类改名。
导入方法代码为:
Vendor('Zend.PHPMailer.classphpmailer');
完整的邮件发送代码:
public function sendmail($sendto_email, $user_name, $subject, $bodyurl)
{
Vendor('Zend.PHPMailer.classphpmailer');
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "你的邮件服务域名"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "XXXX"; // SMTP username 注意:普通邮件认证不需要加 @域名
$mail->Password = "******"; // SMTP password
$mail->From = "axx@xxx.com"; // 发件人邮箱
$mail->FromName = "管理员"; // 发件人
$mail->CharSet = "utf-8"; // 这里指定字符集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email, $user_name); // 收件人邮箱和姓名
$mail->SetFrom('axx@xxx.com', 'XXXXXXX有限公司');
$mail->AddReplyTo("axx@xxx.com", 'xxxxxxxx有限公司');
//$mail->WordWrap = 50; // set word wrap 换行字数
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
// 邮件主题
$mail->Subject = $subject;
// 邮件内容
$mail->Body = '<html><head>
<meta http-equiv="Content-Language" content="zh-cn"/>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<div style="width:60%;padding:30px 20px;background:#F9F9F9;">
<span style="font-weight:bold;font-size:16px;">Hi,' . $user_name . '</span><br/>
欢迎您注册<b>XXX公司网站</b><br/>
请点击下面的连接完成注册(有效期一小时):<br/>
' . $bodyurl . '<br/>
<font style="color:#999;">如果以上链接无法点击,请将上面的地址复制到你的浏览器(如IE)的地址栏完成激活</font><br/>
http://www.XXX.com
</div>
</body>
</html>
';
$mail->AltBody = "text/html";
if (!$mail->Send())
{
$mail->ClearAddresses();
echo "邮件错误信息: " . $mail->ErrorInfo;
exit;
}
else
{
$mail->ClearAddresses();
// $this->assign('waitSecond', 6);
// $this->success("注册成功,系统已经向您的邮箱:{$sendto_email}发送了一封激活邮件!请您尽快激活~~<br />");
$this->redirect('sendhtml', array('send' => 5,'email'=>$sendto_email));
}
}
其次调用发送方法:
$this->sendmail($_POST['email'], $_POST['nickname'], $subject, $bodyurl);