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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< ? 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 ());
}
}