手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

thinkphp5如何发送邮件

时间:2024-10-11 19:37:47

1、thinkphp官方下载thinkphp5,官方网址请百度搜索

thinkphp5如何发送邮件

2、安装PHP运行环境,推荐使用phpstydy,phpstydy官方地址请百度搜索

thinkphp5如何发送邮件

3、安装phpstydy并启用,参考下面的链接

4、解压thinkphp5到网站根目录,如图,指向为访问地址

thinkphp5如何发送邮件

5、下载phpmailer并解压,将phpmailer放至vendor/下

thinkphp5如何发送邮件

6、在\application\index\controller下index.php 捂执涡扔使用自定义函数sendMail('接收邮箱', '标题', '内容&#泌驾台佐39;);

thinkphp5如何发送邮件

7、打开函数文件common.php ,添加脑栲葱蛸函数sendMail代码如下function sendMail($email, $t足毂忍珩itle, $content){ vendor('phpmailer.PHPMailerAutoload'); $config = \think\Db::name('system_config')->select(); $mail = new PHPMailer; $mail->CharSet = 'UTF-8'; $mail->isSMTP(); $mail->SMTPDebug = 0; if($config['is_ssl']){ $mail->SMTPSecure = 'ssl'; } $mail->Debugoutput = 'html'; $mail->Host = $config['smtp']; $mail->Port = $config['email_port']; $mail->SMTPAuth = true; $mail->Username = $config['emailuser']; $mail->Password = $config['emailpass']; $mail->setFrom($config['from_email']); $mail->addAddress($email); $mail->FromName = $config['from_name']; $mail->Subject = $title; $mail->Body = $content; if (!$mail->send()) { // echo "发送失败: " . $mail->ErrorInfo; return false; } else { // echo "发送成功"; return true; }}

thinkphp5如何发送邮件
© 手抄报圈