Mail.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Qii\Library;
  3. /**
  4. * Mail 类
  5. *
  6. *
  7. * @author Jinhui.zhu <jinhui.zhu@live.cn>
  8. * @version $Id: mail.plugin.php,v 1.1 2010/04/23 06:02:12 Jinhui.Zhu Exp $
  9. */
  10. _require(Qii_DIR . "/Library/Third/phpmailer/class.phpmailer.php");
  11. class Mail extends \PHPMailer
  12. {
  13. private $mailConfig;
  14. private $_error;
  15. public function __construct()
  16. {
  17. }
  18. /**
  19. * 设置SMTP
  20. *
  21. * @param Array $mailConfig
  22. */
  23. public function sysSet($mailConfig)
  24. {
  25. $this->mailConfig = $mailConfig;
  26. $this->IsSMTP();
  27. $this->Host = $mailConfig['server'];
  28. $this->Port = $mailConfig['port'];
  29. $this->SMTPAuth = $mailConfig['auth'];
  30. $this->SMTPDebug = 0;
  31. $this->Username = $mailConfig['authUsername'];
  32. $this->Password = $mailConfig['authPassword'];
  33. $this->From = $mailConfig['from'];
  34. $this->FromName = $mailConfig['fromName'];
  35. $this->CharSet = 'UTF-8';
  36. $this->IsHTML(true);
  37. }
  38. /**
  39. * 发送邮件
  40. * @param array $mailInfo
  41. */
  42. public function sendMail($mailInfo)
  43. {
  44. $this->ClearAddresses();
  45. $this->AddAddress($mailInfo['to']);
  46. $this->Subject = $mailInfo['subject'];
  47. $this->Body = $mailInfo['content'];
  48. if(!$this->Send())
  49. {
  50. $this->error($this->ErrorInfo);
  51. return false;
  52. }
  53. return true;
  54. }
  55. /**
  56. * 获取当前SMTP配置
  57. *
  58. * @return Array
  59. */
  60. public function getCurrentConfig()
  61. {
  62. return $this->mailConfig;
  63. }
  64. /**
  65. * 错误信息
  66. *
  67. * @param Mix $error
  68. */
  69. public function error($error)
  70. {
  71. $this->_error[] = $error;
  72. }
  73. /**
  74. * 获取错误信息
  75. *
  76. * @return Array
  77. */
  78. public function getError()
  79. {
  80. return $this->_error;
  81. }
  82. }