Phpmailer.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\extend\email;
  3. class Phpmailer {
  4. public $name = 'PhpMailer';
  5. public $ver = '1.0';
  6. public function submit($to, $title, $body,$config=[])
  7. {
  8. if(empty($config)) {
  9. $config = $GLOBALS['config']['email']['phpmailer'];
  10. $config['nick'] = $GLOBALS['config']['email']['nick'];
  11. }
  12. $mail = new \phpmailer\src\PHPMailer();
  13. //$mail->SMTPDebug = 2;
  14. $mail->isSMTP();
  15. $mail->SMTPAuth = true;
  16. $mail->CharSet = "UTF-8";
  17. $mail->Host = $config['host'];
  18. $mail->SMTPSecure = $config['secure'];
  19. $mail->Port = $config['port'];
  20. $mail->Username = $config['username'];
  21. $mail->Password = $config['password'];
  22. $mail->setFrom($config['username'] , $config['nick']);
  23. $mail->addAddress($to);
  24. $mail->isHTML(true);
  25. $mail->Subject = $title;
  26. $mail->Body = $body;
  27. unset($config);
  28. $res = $mail->send();
  29. if($res===true){
  30. return ['code'=>1,'msg'=>'发送成功'];
  31. }
  32. else{
  33. return ['code'=>102,'msg'=>'发生错误:'. $mail->ErrorInfo ];
  34. }
  35. }
  36. }