Advertisement
Guest User

Untitled

a guest
Oct 4th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. <?php
  2.  
  3. class Email extends PHPMailer
  4. {
  5.  
  6.     public $titulo;
  7.     public $mensagem;
  8.     public $para;
  9.     public $responder;
  10.     public $nome;
  11.     public $assunto;
  12.     private $corpo;
  13.  
  14.     public function __construct()
  15.     {
  16.         parent::__construct();
  17.  
  18.  
  19.     }
  20.  
  21.     public function enviarEmail()
  22.     {
  23.         try {
  24.  
  25.             $CI =& get_instance();
  26.  
  27.             $this->CharSet = $CI->config->item('smtp_charset');
  28.  
  29.             if ($CI->config->item("smtp_auth")) {
  30.                 $this->isSMTP();
  31.                 $this->SMTPAuth = true;
  32.                 $this->Host = $CI->config->item('smtp_host');
  33.                 $this->Password = $CI->config->item('smtp_pwd');
  34.                 $this->Username = $CI->config->item('smtp_username');
  35.                 $this->Port = $CI->config->item("smtp_port");
  36.             } else {
  37.                 $this->isMail();
  38.             }
  39.             $this->setLanguage('pt');
  40.             $this->From = $CI->config->item("smtp_from");
  41.             $this->SMTPSecure = $CI->config->item("smtp_secure");
  42.             $this->Body = $this->template();
  43.             $this->isHTML(true);
  44.             $this->ReplyTo = $this->responder == null ? $CI->config->item('smtp_from') : $this->responder;
  45.             $this->Subject = $this->assunto ? $this->assunto : site_url() . " disse:";
  46.             $this->FromName = $this->nome;
  47.             $this->addAddress($this->para);
  48.            
  49.             if ($CI->config->item('smtp_debug')) {
  50.                 $this->SMTPDebug = 4;
  51.             }
  52.  
  53.             if ($this->send()) {
  54.  
  55.                 echo json_encode(array(
  56.                     'message' => 'Mensagem Enviada!',
  57.                     'code' => 1
  58.                 ));
  59.  
  60.             } else {
  61.                 echo json_encode(array(
  62.                     'message' => $this->ErrorInfo,
  63.                     'code' => 1
  64.                 ));
  65.             };
  66.         } catch (phpmailerException $e) {
  67.             echo json_encode(array(
  68.                 'message' => $e->getMessage(),
  69.                 'code' => $e->getCode()
  70.             ));
  71.         }catch (Exception $e){
  72.             echo json_encode(array(
  73.                 'message' => $e->getMessage(),
  74.                 'code' => $e->getCode()
  75.             ));
  76.         }
  77.  
  78.     }
  79.  
  80.  
  81.     /**
  82.      * Layout do modelo do email
  83.      * @param type $titulo (titulo do corpo)
  84.      * @param type $mensagem (mensagem do corpo, aceita html)
  85.      * @return string
  86.      */
  87.     public function template()
  88.     {
  89.  
  90.         $body = "<h1 style='background:#063346; padding:10px; color:#fff;margin:0; text-align:center;font-family:Heveltica,Arial'>$this->titulo</h1>";
  91.         $body .= "<table style='border:solid 1px #ccc;background:#ebebeb;text-align:center;width:100%; font-family:Heveltica,Arial'>";
  92.         $body .= "<tr>";
  93.         $body .= "<td style='padding:10px'>$this->mensagem</td>";
  94.         $body .= "</tr>";
  95.         $body .= "<tr>";
  96.         $body .= "<td style='padding:10px'><small>Mensagem enviada do site : " . site_url() . "</td>";
  97.         $body .= "</tr>";
  98.         $body .= "</table>";
  99.  
  100.         $this->corpo = $body;
  101.  
  102.         return $this->corpo;
  103.  
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement