Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. <?php
  2. class Email
  3. {
  4. private $to;
  5. private $subject;
  6. private $cc;
  7. private $bcc;
  8. private $html;
  9. private $plainText;
  10. private $replyEmail;
  11. private $replyName;
  12. private $fromEmail;
  13. private $fromName;
  14.  
  15. private $host;
  16. private $username;
  17. private $password;
  18. private $security;
  19. private $port;
  20. private $files;
  21. public function __construct($host, $username, $password, $security, $port)
  22. {
  23. $this->host = $host;
  24. $this->username = $username;
  25. $this->password = $password;
  26. $this->security = $security;
  27. $this->port = $port;
  28.  
  29. $this->to = "";
  30. $this->files = [];
  31. $this->subject = "";
  32. $this->html = "";
  33. $this->plainText = "";
  34. $this->replyEmail = "";
  35. $this->replyName = "";
  36. $this->fromEmail = "";
  37. $this->fromName = "";
  38. $this->cc = [];
  39. $this->bcc = [];
  40. return $this;
  41. }
  42. public function attach($files)
  43. {
  44. if(is_array($files)) {
  45. $this->files += $files;
  46. } else {
  47. $this->files[] = $files;
  48. }
  49. return $this;
  50. }
  51. public function from($email, $name)
  52. {
  53. $this->fromName = $name;
  54. $this->fromEmail = $email;
  55. return $this;
  56. }
  57. public function to($email)
  58. {
  59. $this->to = $email;
  60. return $this;
  61. }
  62. public function cc($cc)
  63. {
  64. if (is_array($cc)) {
  65. $this->cc += $cc;
  66. } else {
  67. $this->cc[] = $cc;
  68. }
  69. return $this;
  70. }
  71. public function bcc($bcc)
  72. {
  73. if (is_array($bcc)) {
  74. $this->bcc += $bcc;
  75. } else {
  76. $this->bcc[] = $bcc;
  77. }
  78. return $this;
  79. }
  80.  
  81. public function subject($subject)
  82. {
  83. $this->subject = $subject;
  84. return $this;
  85. }
  86. public function html($html)
  87. {
  88. $this->html = $html;
  89. return $this;
  90. }
  91. public function plainText($plainText)
  92. {
  93. $this->plainText = $plainText;
  94. return $this;
  95. }
  96.  
  97. public function send()
  98. {/*
  99. echo "Sending email" . PHP_EOL;
  100. echo "Subject: ".$this->subject.PHP_EOL;
  101. echo "To: ".$this->to.PHP_EOL;
  102. echo "Cc: ".implode(",",$this->cc).PHP_EOL;
  103. echo "Bcc: ".implode(",",$this->bcc).PHP_EOL;*/
  104. $mail = new PHPMailer;
  105. $mail->isSMTP();
  106. //$mail->SMTPDebug = 3;
  107. $mail->Host = $this->host;
  108. $mail->SMTPAuth = true;
  109. $mail->Username = $this->username;
  110. $mail->Password = $this->password;
  111. $mail->SMTPAutoTLS = false;
  112. $mail->SMTPSecure = $this->security;
  113. $mail->Port = $this->port;
  114. $mail->CharSet = 'UTF-8';
  115. foreach ($this->bcc as $bcc) {
  116. $mail->addBCC($bcc);
  117. }
  118. foreach ($this->cc as $cc) {
  119. $mail->addCC($cc);
  120. }
  121. if (count($this->files) > 0) {
  122. foreach ($this->files as $file) {
  123. $mail->addAttachment($file);
  124. }
  125. }
  126. $mail->From = $this->fromEmail;
  127. $mail->FromName = $this->fromName;
  128. $mail->addAddress($this->to);
  129. if (!empty($this->replyEmail)) {
  130. $mail->addReplyTo($this->replyEmail, $this->replyName);
  131. }
  132. if(!empty($this->html)) {
  133. $mail->isHTML(true);
  134. $mail->Body = $this->html;
  135. } else {
  136. $mail->Body = $this->plainText;
  137. }
  138. $mail->Subject = $this->subject;
  139. if($mail->send()) {
  140. return true;
  141. } else {
  142. return false;
  143. }
  144. }
  145. }
  146.  
  147.  
  148.  
  149.  
  150. $a = new Email("smtp.gmail.com","contatopillow@gmail.com","123456","ssl","587");
  151. $this->email->to("clientes@bordeaux-bh.com.br")
  152. ->bcc("joao@animatto.com.br")
  153. ->from("noreply@bordeaux-bh.com.br","Contato Bordeaux")
  154. ->subject("Contato Via Site - ".$pagina)
  155. ->html($corpo)
  156. //->attach(PUBLIC_PATH."/images/check.png")
  157. ->send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement