32 lines
1.3 KiB
PHP
32 lines
1.3 KiB
PHP
<?php
|
||
namespace Common\Controller;
|
||
use Think\Controller;
|
||
class Mail extends Controller{
|
||
/**
|
||
* 邮件发送函数
|
||
*/
|
||
function sendMail($to, $title, $content){
|
||
Vendor('PHPMailer.PHPMailerAutoload');
|
||
$mail = new \PHPMailer(); //实例化
|
||
$mail->IsSMTP(); // 启用SMTP
|
||
$mail->Host=C('email.MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例)
|
||
$mail->SMTPAuth =TRUE; //启用smtp认证
|
||
$mail->Username = C('email.MAIL_USERNAME'); //你的邮箱名
|
||
$mail->Password = C('email.MAIL_PASSWORD') ; //邮箱密码
|
||
$mail->From = C('email.MAIL_USERNAME'); //发件人地址(也就是你的邮箱地址)
|
||
$mail->FromName = C('email.MAIL_FROMNAME'); //发件人姓名
|
||
$mail->AddAddress($to,"尊敬的客户");
|
||
//阿里不支持25端口需要开启ssl
|
||
$mail->SMTPSecure = 'ssl';
|
||
$mail->Port = 465;
|
||
//
|
||
$mail->WordWrap = 50; //设置每行字符长度
|
||
$mail->IsHTML(TRUE); // 是否HTML格式邮件
|
||
$mail->CharSet="utf-8"; //设置邮件编码
|
||
$mail->Subject =$title; //邮件主题
|
||
$mail->Body = $content; //邮件内容
|
||
$mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
|
||
return($mail->Send());
|
||
}
|
||
}
|