SendMail.Class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace Mall\Framework\Core;
  3. use Mall\Framework\Mail\Mail;
  4. class SendMail {
  5. private static $_instance;
  6. protected $error;
  7. static public function getInstance()
  8. {
  9. $key = md5('sendmail');
  10. if (!self::$_instance[$key] instanceof self) {
  11. self::$_instance[$key] = new self;
  12. }
  13. return self::$_instance[$key];
  14. }
  15. public function mail($title, $email, $html, $sign=null)
  16. {
  17. $key = md5('mail');
  18. if (!self::$_instance[$key] instanceof self) {
  19. $options = Config::getInstance()->get('mail');
  20. self::$_instance[$key] = new Mail($options['mailer'], $options['delimiter'], $options['charset'], $options['from'], $options['sign'], $options['smtp_host'], $options['smtp_port'], $options['smtp_auth'], $options['smtp_username'], $options['smtp_password']);
  21. }
  22. self::$_instance[$key]->execute($email, $title, $html);
  23. if ($this->error = self::$_instance[$key]->error()) {
  24. return false;
  25. }
  26. return true;
  27. }
  28. public function getError()
  29. {
  30. return $this->error;
  31. }
  32. /**
  33. * 邮箱验证码
  34. * @param $nickname
  35. * @param $code
  36. * @return string
  37. */
  38. public function emailCode($nickname, $code)
  39. {
  40. return "
  41. <div style='width:700px;height:240px;padding:0 30px;color:#444;font-size:15px;padding-top:20px;'>
  42. <p style='font-size: 16px;'>
  43. 亲爱的{$nickname}:
  44. </p>
  45. <div style='width:630px;margin-top:20px;color:#444;word-wrap:break-word;'>
  46. <p style='margin-top:20px;'>您的验证码为:{$code}</p>
  47. </div>
  48. </div>
  49. ";
  50. }
  51. /**
  52. * 重置密码
  53. * @param $nickname
  54. * @param $url
  55. * @return string
  56. */
  57. public function userResetPw($nickname, $url)
  58. {
  59. return "
  60. <div style='width:700px;height:240px;padding:0 30px;color:#444;font-size:15px;padding-top:10px;'>
  61. <h4 style='font-size: 15px; padding:0; margin:0;'>亲爱的 {$nickname},您好:</h4>
  62. <p style='font-size: 14px; margin: 3px 0; padding-left:30px;'>您的账号正在进行找回密码操作!</p>
  63. <div style='width:630px;margin-top:20px; padding-left:30px;color:#444;word-wrap:break-word;'>
  64. <p style='text-align: center;width:630px;'>
  65. <a href='" . $url . "' style='margin-left:220px;padding: 6px; color:white;text-decoration: none;width:130px;height:30px;display:block;background: #65A8FF;border-radius:10px;'>
  66. <span style='vertical-align: middle;'>点击重置密码</span>
  67. </a>
  68. </p>
  69. <div style='border-left: 5px solid #007AFF;padding-left:10px; font-size: 14px;'>
  70. <p style='margin:0; padding:0;'>如果您点击上述链接无效,请将下面的链接复制到浏览器地址栏中访问:</p>
  71. <p>{$url}</p>
  72. </div>
  73. <p style='color:grey;margin:0;'>
  74. <span>为保障您的账号安全性,以上链接有效期为 3 天。</span><br/>
  75. </p>
  76. </div>
  77. </div>
  78. ";
  79. }
  80. public function html($content, $sitename, $info)
  81. {
  82. $logo = $logo = PROJECT_IMG_DOMAIN . "assets/mail/img/logo.png";
  83. $copyright = $copyright = "Copyright © 2017 北京猫逛科技有限公司";
  84. $sitename = $sitename ?: '北京猫逛科技有限公司';
  85. return
  86. "<html xmlns='http://www.w3.org/1999/xhtml'>
  87. <head>
  88. <meta http-equiv='Content-Type' content='text/html; charset=3DUTF-8'/>
  89. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  90. <title>{$sitename}</title>
  91. </head>
  92. <body style='margin:0;padding:0;'>
  93. <table width='900' cellpadding='0' cellspacing='0' border='0'>
  94. <tr>
  95. <td style='width:900px;background-color:#f5f3f0;'>
  96. <div style='padding:50px 100px;'>
  97. <div style='width:700px;min-height:600px; _height:600px;background-color:#fff;font-family:微软雅黑;overflow:hidden;'>
  98. <div style='width:600px;height:80px;'>
  99. <div style='float:left;'>
  100. <img src='{$logo}' width='245' height='30' style='padding:25px 0 0 30px;' />
  101. </div>
  102. <div style='padding:32px 0 0 280px;'>
  103. <span>这里是占位符</span>
  104. </div>
  105. </div>
  106. <div style='width:700px;height:200px;padding:0 30px;'>
  107. <div style='width:640px;height:200px;background-image:url(http://www{$domainSuffix}/assets/mail/img/mail.png);'>
  108. <div style='width:545px;height:200px;padding-top:70px;margin-left:95px;overflow:hidden;'>
  109. <span style='padding-left:130px;font-size:32px;color:#fff;font-weight:bold;white-space:nowrap;'>{$sitename}</span>
  110. <br />
  111. <span style='padding-left:132px;font-size:18px;color:#feebeb;'>{$info}</span>
  112. </div>
  113. </div>
  114. </div>
  115. {$content}
  116. <div style='width:700px;height:30px;padding-left:500px;margin-top:20px;;color:#444;'>
  117. <span>{$sitename}团队</span>
  118. </div>
  119. </div>
  120. <div style='text-align:center;color:#444;font-size:12px;font-family:微软雅黑;margin-top:20px;padding-top:20px;'>
  121. {$copyright}
  122. </div>
  123. </div>
  124. </td>
  125. </tr>
  126. </table>
  127. </body>
  128. </html>";
  129. }
  130. }