Email.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Service\Lib;
  3. use Dever;
  4. class Email
  5. {
  6. public function send()
  7. {
  8. $uid = Dever::input('uid');
  9. $feedback_id = Dever::input('feedback_id');
  10. $email = Dever::input('email');
  11. $user = Dever::db('passport/user')->one($uid);
  12. if ($user['email'] != $email) {
  13. Dever::db('passport/user')->update(array('where_id' => $uid, 'email' => $email));
  14. }
  15. $info = Dever::db('service/feedback')->one($feedback_id);
  16. $product = Dever::db('service/product')->one($info['product_id']);
  17. //$pdf = Dever::local($info['pdf']);
  18. $pdf = str_replace('{uploadRes}', Dever::data() . 'upload/', $info['pdf']);
  19. Dever::apply('src/PHPMailer', 'email');
  20. Dever::apply('src/Exception', 'email');
  21. Dever::apply('src/SMTP', 'email');
  22. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  23. $mail->isSMTP();
  24. //$mail->SMTPDebug = 2;
  25. $mail->CharSet = 'UTF-8';
  26. $mail->Host = 'smtp.exmail.qq.com';
  27. $mail->Port = 465;
  28. $mail->SMTPSecure = 'ssl';
  29. $mail->SMTPAuth = true;
  30. $mail->Username = 'miniapps@jiazhihome.com';
  31. $mail->Password = 'ILoveJiazhi0426';
  32. $mail->setFrom('miniapps@jiazhihome.com', '家芝服务');
  33. $mail->addAddress($email, $user['username']);
  34. $name = '家芝'.$product['name'].'方案';
  35. $mail->Subject = "=?utf-8?B?" . base64_encode($name) . "?=";
  36. $mail->Body = '您好,'.$user['username'].',请见附件。';
  37. $mail->addAttachment($pdf);
  38. if (!$mail->send()) {
  39. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  40. } else {
  41. return 'ok';
  42. }
  43. }
  44. }