Mail.php 928 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. use Nette\Mail\Message;
  3. use Nette\Mail\SmtpMailer;
  4. use \app\model\SettingModel;
  5. class Mail
  6. {
  7. public static function send($to = "", $text = ""): bool
  8. {
  9. $mail = new Message;
  10. $send_mail = SettingModel::Config('smtp_email');
  11. $mail->setFrom(SettingModel::Config('title','')." <$send_mail>")
  12. ->addTo($to)
  13. ->setSubject(SettingModel::Config('title','') . '动态令牌')
  14. ->setHtmlBody($text);
  15. $mailer = new SmtpMailer([
  16. 'port' => SettingModel::Config('smtp_port'),
  17. 'host' => SettingModel::Config('smtp_host'),
  18. 'username' => SettingModel::Config('smtp_email'),
  19. 'password' => SettingModel::Config('smtp_password'),
  20. 'secure' => 'ssl',
  21. ]);
  22. try {
  23. $mailer->send($mail);
  24. } catch (\Throwable $th) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. }