酒店预订平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

198 líneas
4.0 KiB

  1. <?php
  2. /***************************************************\
  3. *
  4. * Mailer (https://github.com/txthinking/Mailer)
  5. *
  6. * A lightweight PHP SMTP mail sender.
  7. * Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821
  8. *
  9. * Support html body, don't worry that the receiver's
  10. * mail client can't support html, because Mailer will
  11. * send both text/plain and text/html body, so if the
  12. * mail client can't support html, it will display the
  13. * text/plain body.
  14. *
  15. * Create Date 2012-07-25.
  16. * Under the MIT license.
  17. *
  18. \***************************************************/
  19. namespace Tx;
  20. use Psr\Log\LoggerInterface;
  21. use \Tx\Mailer\Message;
  22. use \Tx\Mailer\SMTP;
  23. /**
  24. * Class Mailer
  25. *
  26. * This class provides the Mailer public methods for backwards compatibility, but it is recommended
  27. * that you use the Tx\Mailer\SMTP and Tx\Mailer\Message classes going forward
  28. *
  29. * @package Tx
  30. */
  31. class Mailer
  32. {
  33. /**
  34. * SMTP Class
  35. * @var SMTP
  36. */
  37. protected $smtp;
  38. /**
  39. * Mail Message
  40. * @var Message
  41. */
  42. protected $message;
  43. /**
  44. * construct function
  45. * @param LoggerInterface $logger
  46. */
  47. public function __construct(LoggerInterface $logger=null)
  48. {
  49. $this->smtp = new SMTP($logger);
  50. $this->message = new Message();
  51. }
  52. /**
  53. * set server and port
  54. * @param string $host server
  55. * @param int $port port
  56. * @param string $secure ssl tls tlsv1.0 tlsv1.1 tlsv1.2
  57. * @return $this
  58. */
  59. public function setServer($host, $port, $secure=null)
  60. {
  61. $this->smtp->setServer($host, $port, $secure);
  62. return $this;
  63. }
  64. /**
  65. * auth with server
  66. * @param string $username
  67. * @param string $password
  68. * @return $this
  69. */
  70. public function setAuth($username, $password)
  71. {
  72. $this->smtp->setAuth($username, $password);
  73. return $this;
  74. }
  75. /**
  76. * auth oauthbearer with server
  77. * @param string $accessToken
  78. * @return $this
  79. */
  80. public function setOAuth($accessToken)
  81. {
  82. $this->smtp->setOAuth($accessToken);
  83. return $this;
  84. }
  85. /**
  86. * set mail from
  87. * @param string $name
  88. * @param string $email
  89. * @return $this
  90. */
  91. public function setFrom($name, $email)
  92. {
  93. $this->message->setFrom($name, $email);
  94. return $this;
  95. }
  96. /**
  97. * set fake mail from
  98. * @param string $name
  99. * @param string $email
  100. * @return $this
  101. */
  102. public function setFakeFrom($name, $email)
  103. {
  104. $this->message->setFakeFrom($name, $email);
  105. return $this;
  106. }
  107. /**
  108. * add mail receiver
  109. * @param string $name
  110. * @param string $email
  111. * @return $this
  112. */
  113. public function addTo($name, $email)
  114. {
  115. $this->message->addTo($name, $email);
  116. return $this;
  117. }
  118. /**
  119. * add cc mail receiver
  120. * @param string $name
  121. * @param string $email
  122. * @return $this
  123. */
  124. public function addCc($name, $email)
  125. {
  126. $this->message->addCc($name, $email);
  127. return $this;
  128. }
  129. /**
  130. * add bcc mail receiver
  131. * @param string $name
  132. * @param string $email
  133. * @return $this
  134. */
  135. public function addBcc($name, $email)
  136. {
  137. $this->message->addBcc($name, $email);
  138. return $this;
  139. }
  140. /**
  141. * set mail subject
  142. * @param string $subject
  143. * @return $this
  144. */
  145. public function setSubject($subject)
  146. {
  147. $this->message->setSubject($subject);
  148. return $this;
  149. }
  150. /**
  151. * set mail body
  152. * @param string $body
  153. * @return $this
  154. */
  155. public function setBody($body)
  156. {
  157. $this->message->setBody($body);
  158. return $this;
  159. }
  160. /**
  161. * add mail attachment
  162. * @param $name
  163. * @param $path
  164. * @return $this
  165. */
  166. public function addAttachment($name, $path)
  167. {
  168. $this->message->addAttachment($name, $path);
  169. return $this;
  170. }
  171. /**
  172. * Send the message...
  173. * @return boolean
  174. */
  175. public function send()
  176. {
  177. return $this->smtp->send($this->message);
  178. }
  179. }