Email.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Option\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. $url = Dever::url();
  15. if (strstr($url, 'uat')) {
  16. $host = 'http://qiquan.uat.churenyiliao.com/';
  17. } else {
  18. $host = 'http://qiquan.churenyiliao.com/';
  19. }
  20. $signature = Dever::decode($signature);
  21. $temp = explode('|||', $signature);
  22. $code = $temp[2];
  23. $state = Dever::load('passport/reg')->code($code);
  24. if (!$state) {
  25. //Dever::alert('您的验证信息已失效,请重新发送验证邮件');
  26. }
  27. $check = Dever::db('option/account')->find(array('email' => $temp[1]));
  28. if (!$check) {
  29. Dever::location($host . 'pages/app/checkemail/checkemail/?email='.$temp[1].'&status=2');
  30. Dever::alert('您的验证信息已失效,请重新发送验证邮件');
  31. }
  32. $where['where_id'] = $temp[0];
  33. //$where['email'] = $temp[1];
  34. $where['is_email'] = 1;
  35. Dever::db('option/account')->update($where);
  36. Dever::location($host . 'pages/app/checkemail/checkemail/?email='.$temp[1].'&status=1');
  37. echo '您的邮件:'.$temp[1].',已经验证成功。请登录期权管理系统查询。';die;
  38. }
  39. public function renzheng()
  40. {
  41. $email = Dever::input('email');
  42. $username = Dever::input('username');
  43. $code = Dever::input('code');
  44. $aid = Dever::input('aid');
  45. $email = base64_decode($email);
  46. $config = Dever::config('base', 'project')->email['option'];
  47. $title = $config['title'];
  48. $content = $config['content'];
  49. $signature = Dever::encode($aid . '|||' . $email . '|||' . $code);
  50. $link = Dever::url($config['link'] . '?signature=' . $signature);
  51. $date = date('Y-m-d H:i:s');
  52. $content = str_replace('{link}', $link, $content);
  53. $content = str_replace('{username}', $username, $content);
  54. $content = str_replace('{date}', $date, $content);
  55. $this->send($email, $username, $title, $content);
  56. }
  57. public function send($email, $username, $title, $content)
  58. {
  59. $config = Dever::config('base', 'project')->email;
  60. Dever::apply('src/PHPMailer', 'email');
  61. Dever::apply('src/Exception', 'email');
  62. Dever::apply('src/SMTP', 'email');
  63. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  64. $mail->isSMTP();
  65. //$mail->SMTPDebug = 2;
  66. $mail->CharSet = 'UTF-8';
  67. $mail->Host = $config['smtp'];
  68. $mail->Port = 465;
  69. $mail->SMTPSecure = 'ssl';
  70. $mail->SMTPAuth = true;
  71. $mail->Username = $config['username'];
  72. $mail->Password = $config['password'];
  73. $mail->setFrom($config['from'][0], '期权管理系统');
  74. $mail->addAddress($email, $username);
  75. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  76. $mail->Body = $content;
  77. $mail->isHTML(true);
  78. //$mail->addAttachment($file);
  79. if (!$mail->send()) {
  80. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  81. } else {
  82. return 'ok';
  83. }
  84. }
  85. }