Email.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Passport\Lib;
  3. use Dever;
  4. use Dever\Session\Oper as Save;
  5. class Email
  6. {
  7. public function forget()
  8. {
  9. $email = Dever::input('email');
  10. $code = Dever::input('code');
  11. $email = base64_decode($email);
  12. $config = Dever::config('base', 'project')->email['forget'];
  13. $title = $config['title'];
  14. $content = $config['content'];
  15. $signature = Dever::encode($email . '|||' . $code);
  16. $link = Dever::url($config['link'] . '?email='.$email . '&signature=' . $signature);
  17. $content = str_replace('{link}', $link, $content);
  18. $this->send($email, $title, $content);
  19. }
  20. public function send($email, $title, $content)
  21. {
  22. $user = Dever::db('passport/user')->one(array('email' => $email));
  23. if (!$user) {
  24. Dever::alert('该邮箱还未注册');
  25. }
  26. $config = Dever::config('base', 'project')->email;
  27. Dever::apply('src/PHPMailer', 'email');
  28. Dever::apply('src/Exception', 'email');
  29. Dever::apply('src/SMTP', 'email');
  30. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  31. $mail->isSMTP();
  32. //$mail->SMTPDebug = 2;
  33. $mail->CharSet = 'UTF-8';
  34. $mail->Host = $config['smtp'];
  35. $mail->Port = 465;
  36. $mail->SMTPSecure = 'ssl';
  37. $mail->SMTPAuth = true;
  38. $mail->Username = $config['username'];
  39. $mail->Password = $config['password'];
  40. $mail->setFrom($config['from'][0], $config['from'][1]);
  41. $mail->addAddress($user['email'], $user['username']);
  42. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  43. $mail->Body = $content;
  44. //$mail->addAttachment($file);
  45. if (!$mail->send()) {
  46. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  47. } else {
  48. return 'ok';
  49. }
  50. }
  51. }