Email.php 1.7 KB

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