php发送邮件
发布时间:2020-12-13 21:29:13 所属栏目:PHP教程 来源:网络整理
导读:? php // +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2016 http://thinkphp
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: 流年 <[email?protected]> // +---------------------------------------------------------------------- use PHPMailerPHPMailerPHPMailer; // 应用公共文件 function mailto($to,$title,$content) { Vendor(‘phpmailer.phpmailer‘); $mail = new PHPMailer(); //实例化 $mail->IsSMTP(); // 启用SMTP $mail->Host = ‘smtp.qq.com‘; //SMTP服务器 以126邮箱为例子 $mail->Port = 465; //邮件发送端口 $mail->SMTPAuth = true; //启用SMTP认证 $mail->SMTPSecure = "ssl"; // 设置安全验证方式为ssl $mail->CharSet = "UTF-8"; //字符集 $mail->Encoding = "base64"; //编码方式 $mail->Username = ‘[email?protected]‘; //你的邮箱 $mail->Password = ‘zgkriozgyulkbaad‘; //你的邮箱授权码 $mail->Subject = $title; //邮件标题 $mail->From = ‘[email?protected]‘; //发件人地址(也就是你的邮箱) $mail->FromName = ‘小张‘; //发件人姓名 $mail->AddAddress($to,"亲"); //添加收件人(地址,昵称) $mail->IsHTML(true); //支持html格式内容 $mail->Body = $content; //邮件主体内容 //发送成功就删除 if ($mail->Send()) { return "发送成功"; } else { return "Mailer Error: " . $mail->ErrorInfo; // 输出错误信息 } } 1、安装:composer require phpmailer/phpmailer2、引入:use PHPMailerPHPMailerPHPMailer3、在 application/common.php 文件下写以下代码,在common中查看在Thinkphp5框架中任意地方都可以用以下方式调用:mailto($to,$title,$content) //地址 标题 内容(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |