mailerChajian.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. PHPMailer 读取插件类
  4. */
  5. include_once(ROOT_PATH.'/include/PHPMailer/class.phpmailer.php');
  6. include_once(ROOT_PATH.'/include/PHPMailer/class.smtp.php');
  7. class mailerChajian extends Chajian{
  8. private $mail;
  9. private $mailbool;
  10. public function initChajian(){
  11. $this->mail = new PHPMailer();
  12. $this->mail->IsSMTP();
  13. $this->mail->SMTPAuth = true;
  14. $this->mail->SMTPDebug = 0;
  15. $this->mail->CharSet = 'UTF-8';
  16. $this->mailbool = false;
  17. }
  18. public function setHost($host, $port=25, $secure=''){
  19. $this->mail->Host = $host;
  20. $this->mail->SMTPSecure = $secure;
  21. $this->mail->Port = (int)$port;
  22. }
  23. public function setUser($email, $pass){
  24. $this->mail->Username = $email;
  25. $this->mail->Password = $pass;
  26. $this->setFrom($email);
  27. $this->addReplyTo($email);
  28. }
  29. //发件人邮箱地址
  30. public function setFrom($from, $name=''){
  31. $this->mail->SetFrom($from, $this->tojoin($name));
  32. }
  33. //设置回复
  34. public function addReplyTo($address, $name=''){
  35. $this->mail->AddReplyTo($address, $this->tojoin($name));
  36. }
  37. //添加抄送
  38. public function addCC($address, $name=''){
  39. $a1 = explode(',', $address);
  40. $n1 = array();
  41. if($name != '')$n1 = explode(',', $name);
  42. for($i=0; $i<count($a1); $i++){
  43. $na = '';
  44. if(isset($n1[$i]))$na = $n1[$i];
  45. $this->mail->AddCC($a1[$i], $this->tojoin($na));
  46. }
  47. }
  48. //添加秘密送
  49. public function addBCC($address, $name=''){
  50. $a1 = explode(',', $address);
  51. $n1 = array();
  52. if($name != '')$n1 = explode(',', $name);
  53. for($i=0; $i<count($a1); $i++){
  54. $na = '';
  55. if(isset($n1[$i]))$na = $n1[$i];
  56. $this->mail->AddBCC($a1[$i], $this->tojoin($na));
  57. }
  58. }
  59. //添加收件人
  60. public function addAddress($address, $name=''){
  61. $a1 = explode(',', $address);
  62. $n1 = array();
  63. if($name != '')$n1 = explode(',', $name);
  64. for($i=0; $i<count($a1); $i++){
  65. $na = '';
  66. if(isset($n1[$i]))$na = $n1[$i];
  67. $this->mail->AddAddress($a1[$i], $this->tojoin($na));
  68. }
  69. }
  70. //添加附件
  71. public function addAttachment($address, $name=''){
  72. if($this->rock->isempt($address))return;
  73. $a1 = explode(',', $address);
  74. $n1 = array();
  75. if($name != '')$n1 = explode(',', $name);
  76. for($i=0; $i<count($a1); $i++){
  77. $na = '';
  78. if(isset($n1[$i]))$na = $n1[$i];
  79. $this->mail->AddAttachment(ROOT_PATH.'/'.$a1[$i], $this->tojoin($na));
  80. }
  81. }
  82. //发送邮件
  83. public function sendMail($Subject, $body=''){
  84. $this->mail->Subject = $this->tojoin($Subject);
  85. $this->mail->Body = $body;
  86. $this->mail->IsHTML(true);
  87. $this->mailbool = $this->mail->Send();
  88. }
  89. public function isSuccess(){
  90. return $this->mailbool;
  91. }
  92. public function getErrror(){
  93. return $this->mail->ErrorInfo;
  94. }
  95. private function tojoin($name='')
  96. {
  97. if($name=='')return '';
  98. return "=?UTF-8?B?".base64_encode($name)."?=";
  99. }
  100. }
粤ICP备19079148号