Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Email
- {
- private $to;
- private $subject;
- private $cc;
- private $bcc;
- private $html;
- private $plainText;
- private $replyEmail;
- private $replyName;
- private $fromEmail;
- private $fromName;
- private $host;
- private $username;
- private $password;
- private $security;
- private $port;
- private $files;
- public function __construct($host, $username, $password, $security, $port)
- {
- $this->host = $host;
- $this->username = $username;
- $this->password = $password;
- $this->security = $security;
- $this->port = $port;
- $this->to = "";
- $this->files = [];
- $this->subject = "";
- $this->html = "";
- $this->plainText = "";
- $this->replyEmail = "";
- $this->replyName = "";
- $this->fromEmail = "";
- $this->fromName = "";
- $this->cc = [];
- $this->bcc = [];
- return $this;
- }
- public function attach($files)
- {
- if(is_array($files)) {
- $this->files += $files;
- } else {
- $this->files[] = $files;
- }
- return $this;
- }
- public function from($email, $name)
- {
- $this->fromName = $name;
- $this->fromEmail = $email;
- return $this;
- }
- public function to($email)
- {
- $this->to = $email;
- return $this;
- }
- public function cc($cc)
- {
- if (is_array($cc)) {
- $this->cc += $cc;
- } else {
- $this->cc[] = $cc;
- }
- return $this;
- }
- public function bcc($bcc)
- {
- if (is_array($bcc)) {
- $this->bcc += $bcc;
- } else {
- $this->bcc[] = $bcc;
- }
- return $this;
- }
- public function subject($subject)
- {
- $this->subject = $subject;
- return $this;
- }
- public function html($html)
- {
- $this->html = $html;
- return $this;
- }
- public function plainText($plainText)
- {
- $this->plainText = $plainText;
- return $this;
- }
- public function send()
- {/*
- echo "Sending email" . PHP_EOL;
- echo "Subject: ".$this->subject.PHP_EOL;
- echo "To: ".$this->to.PHP_EOL;
- echo "Cc: ".implode(",",$this->cc).PHP_EOL;
- echo "Bcc: ".implode(",",$this->bcc).PHP_EOL;*/
- $mail = new PHPMailer;
- $mail->isSMTP();
- //$mail->SMTPDebug = 3;
- $mail->Host = $this->host;
- $mail->SMTPAuth = true;
- $mail->Username = $this->username;
- $mail->Password = $this->password;
- $mail->SMTPAutoTLS = false;
- $mail->SMTPSecure = $this->security;
- $mail->Port = $this->port;
- $mail->CharSet = 'UTF-8';
- foreach ($this->bcc as $bcc) {
- $mail->addBCC($bcc);
- }
- foreach ($this->cc as $cc) {
- $mail->addCC($cc);
- }
- if (count($this->files) > 0) {
- foreach ($this->files as $file) {
- $mail->addAttachment($file);
- }
- }
- $mail->From = $this->fromEmail;
- $mail->FromName = $this->fromName;
- $mail->addAddress($this->to);
- if (!empty($this->replyEmail)) {
- $mail->addReplyTo($this->replyEmail, $this->replyName);
- }
- if(!empty($this->html)) {
- $mail->isHTML(true);
- $mail->Body = $this->html;
- } else {
- $mail->Body = $this->plainText;
- }
- $mail->Subject = $this->subject;
- if($mail->send()) {
- return true;
- } else {
- return false;
- }
- }
- }
- $a = new Email("smtp.gmail.com","contatopillow@gmail.com","123456","ssl","587");
- $this->email->to("clientes@bordeaux-bh.com.br")
- ->bcc("joao@animatto.com.br")
- ->from("noreply@bordeaux-bh.com.br","Contato Bordeaux")
- ->subject("Contato Via Site - ".$pagina)
- ->html($corpo)
- //->attach(PUBLIC_PATH."/images/check.png")
- ->send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement