Email.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Email
  5. {
  6. # 修改邮箱
  7. public function act_api()
  8. {
  9. //$signature = Dever::input('signature');
  10. $signature = $_GET['signature'];
  11. if (!$signature) {
  12. Dever::alert('您的验证信息已失效,请重新发送验证邮件');
  13. }
  14. $signature = Dever::decode($signature);
  15. $temp = explode('|||', $signature);
  16. $code = $temp[2];
  17. $state = Dever::load('passport/reg')->code($code);
  18. if (!$state) {
  19. Dever::alert('您的验证信息已失效,请重新发送验证邮件');
  20. }
  21. $check = Dever::db('agent/member')->find(array('email' => $temp[1]));
  22. if ($check) {
  23. Dever::alert('该邮箱已被认证');
  24. }
  25. $where['where_id'] = $temp[0];
  26. $where['email'] = $temp[1];
  27. Dever::db('agent/member')->update($where);
  28. return '邮箱认证成功';
  29. }
  30. public function renzheng()
  31. {
  32. $email = Dever::input('email');
  33. $username = Dever::input('username');
  34. $code = Dever::input('code');
  35. $mid = Dever::input('mid');
  36. $email = base64_decode($email);
  37. $config = Dever::config('base', 'project')->email['agent'];
  38. $title = $config['title'];
  39. $content = $config['content'];
  40. $signature = Dever::encode($mid . '|||' . $email . '|||' . $code);
  41. $link = Dever::url($config['link'] . '?signature=' . $signature);
  42. $content = str_replace('{link}', $link, $content);
  43. $this->send($email, $username, $title, $content);
  44. }
  45. public function send($email, $username, $title, $content)
  46. {
  47. $config = Dever::config('base', 'project')->email;
  48. Dever::apply('src/PHPMailer', 'email');
  49. Dever::apply('src/Exception', 'email');
  50. Dever::apply('src/SMTP', 'email');
  51. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  52. $mail->isSMTP();
  53. //$mail->SMTPDebug = 2;
  54. $mail->CharSet = 'UTF-8';
  55. $mail->Host = $config['smtp'];
  56. $mail->Port = 465;
  57. $mail->SMTPSecure = 'ssl';
  58. $mail->SMTPAuth = true;
  59. $mail->Username = $config['username'];
  60. $mail->Password = $config['password'];
  61. $mail->setFrom($config['from'][0], $config['from'][1]);
  62. $mail->addAddress($email, $username);
  63. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  64. $mail->Body = $content;
  65. //$mail->addAttachment($file);
  66. if (!$mail->send()) {
  67. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  68. } else {
  69. return 'ok';
  70. }
  71. }
  72. }