You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB
PHTML

5 years ago
<?php
namespace App\Controller;
use Think\Controller;
/**
* 首页
*/
class SendMailController extends BaseController {
function sendMail($to,$rand) {
Vendor('phpmailer.PHPMailerAutoload');
$mail = new \phpmailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host=C('email_set.smtp'); //smtp服务器的名称这里以126邮箱为例smtp.126.com
$mail->SMTPAuth = TRUE;//C('MAIL_SMTPAUTH'); //启用smtp认证
$mail->Username = C('email_set.smtp_account'); //你的邮箱名
$mail->Password = C('email_set.smtp_password') ; //邮箱密码
$mail->From = C('email_set.smtp_account'); //发件人地址(也就是你的邮箱地址)
$mail->FromName = C('email_set.smtp_name'); //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML(TRUE); // 是否HTML格式邮件
$mail->CharSet='utf-8'; //设置邮件编码
$mail->Subject =C('email_set.title'); //邮件主题
$content=M("tool",'tab_')->where(array('name'=>'email_set'))->getField('template');
$reg="/#code#/";
$content=preg_replace($reg,$rand,$content);
$mail->Body = $content; //邮件内容
$c = strip_tags($content);
$mail->AltBody = $c; //邮件正文不支持HTML的备用显示
return($mail->Send());
}
}