| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- * User: nickbai
- * Date: 2017/10/24 10:46
- * Email: 1902822973@qq.com
- */
- namespace app\index\controller;
- use think\Controller;
- use Xmail\PHPMailer;
- class Email extends Controller
- {
- // 发送邮件
- public function email(){
- $email=input("param.email/s");//获取收件人邮箱
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->isHTML(true);
- $mail->AltBody = "更好地查看这封邮件,请打开HTML兼容视图"; // optional, comment out and test
- $mail->CharSet = 'utf-8'; // 编码格式为utf8,不设置编码的话,中文会出现乱码
- $mail->SMTPDebug = 0; // enables SMTP debug information
- $mail->SMTPAuth = true; // enable SMTP authentication
- $mail->Host = "smtp.163.com"; // 发送方的SMTP服务器地址
- $mail->Port = 25; // 端口
- $mail->Password = "jonlin2468"; //客户端授权密码,而不是邮箱的登录密码!
- $mail->Username = "jonlinhuang@163.com"; // 发件人邮箱
- $mail->SetFrom('jonlinhuang@163.com', '安全猫-系统邮件'); // 安全猫科技有限公司co.ltd
- $code=rand(100000,999999);
- session('code', $code, 1800);
- $mail->Subject = '邮箱验证';
- $mail->AddAddress($email);
- $mail->MsgHTML('邮箱验证码 <b>您的验证码是:'.$code.'</b>,30分钟内有效,如果非本人操作无需理会!');
- $res = $mail->send();
- if($res == true){
- return "发送成功";
- }else{
- echo "Message could not be sent.";
- echo "Mailer Error: " . $mail->ErrorInfo;// 输出错误信息
- }
- }
- }
|