Emailconfig.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2020/2/4
  6. * Time: 12:47
  7. */
  8. namespace app\common\model;
  9. use think\Env;
  10. use think\Model;
  11. class Emailconfig extends Model
  12. {
  13. protected $autoWriteTimestamp = false;
  14. //发送邮箱激活邮件
  15. public static function sendemail($to_email, $code, $token)
  16. {
  17. $activation_url = url('user/common/activation', '', false, true) . '?code=' . $code . '&name=' . $to_email . '&__token__=' . $token;
  18. $data = self::get(1);
  19. $title = $data['title'];
  20. $content = str_replace(['{nickname}', '{passport}', '{activation_url}', '{email}', '{time}'], [$to_email, $to_email, $activation_url, $to_email, date('Y-m-d H:i:s', time())], $data['content']);
  21. $from_email = $data['from_email'];
  22. $from_name = $data['from_name'];
  23. $smtp = $data['smtp'];
  24. $username = $data['username'];
  25. $password = $data['password'];
  26. return SendMail($to_email, $title, $content, $from_email, $from_name, $smtp, $username, $password);
  27. }
  28. //from_email
  29. public function getFromEmailAttr($value, $data)
  30. {
  31. return $value ?: Env::get('email_account');
  32. }
  33. //username
  34. public function getUsernameAttr($value, $data)
  35. {
  36. return $value ?: Env::get('email_username');
  37. }
  38. //password
  39. public function getPasswordAttr($value, $data)
  40. {
  41. return $value ?: Env::get('email_password');
  42. }
  43. }