Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Email extends PHPMailer
- {
- public $titulo;
- public $mensagem;
- public $para;
- public $responder;
- public $nome;
- public $assunto;
- private $corpo;
- public function __construct()
- {
- parent::__construct();
- }
- public function enviarEmail()
- {
- try {
- $CI =& get_instance();
- $this->CharSet = $CI->config->item('smtp_charset');
- if ($CI->config->item("smtp_auth")) {
- $this->isSMTP();
- $this->SMTPAuth = true;
- $this->Host = $CI->config->item('smtp_host');
- $this->Password = $CI->config->item('smtp_pwd');
- $this->Username = $CI->config->item('smtp_username');
- $this->Port = $CI->config->item("smtp_port");
- } else {
- $this->isMail();
- }
- $this->setLanguage('pt');
- $this->From = $CI->config->item("smtp_from");
- $this->SMTPSecure = $CI->config->item("smtp_secure");
- $this->Body = $this->template();
- $this->isHTML(true);
- $this->ReplyTo = $this->responder == null ? $CI->config->item('smtp_from') : $this->responder;
- $this->Subject = $this->assunto ? $this->assunto : site_url() . " disse:";
- $this->FromName = $this->nome;
- $this->addAddress($this->para);
- if ($CI->config->item('smtp_debug')) {
- $this->SMTPDebug = 4;
- }
- if ($this->send()) {
- echo json_encode(array(
- 'message' => 'Mensagem Enviada!',
- 'code' => 1
- ));
- } else {
- echo json_encode(array(
- 'message' => $this->ErrorInfo,
- 'code' => 1
- ));
- };
- } catch (phpmailerException $e) {
- echo json_encode(array(
- 'message' => $e->getMessage(),
- 'code' => $e->getCode()
- ));
- }catch (Exception $e){
- echo json_encode(array(
- 'message' => $e->getMessage(),
- 'code' => $e->getCode()
- ));
- }
- }
- /**
- * Layout do modelo do email
- * @param type $titulo (titulo do corpo)
- * @param type $mensagem (mensagem do corpo, aceita html)
- * @return string
- */
- public function template()
- {
- $body = "<h1 style='background:#063346; padding:10px; color:#fff;margin:0; text-align:center;font-family:Heveltica,Arial'>$this->titulo</h1>";
- $body .= "<table style='border:solid 1px #ccc;background:#ebebeb;text-align:center;width:100%; font-family:Heveltica,Arial'>";
- $body .= "<tr>";
- $body .= "<td style='padding:10px'>$this->mensagem</td>";
- $body .= "</tr>";
- $body .= "<tr>";
- $body .= "<td style='padding:10px'><small>Mensagem enviada do site : " . site_url() . "</td>";
- $body .= "</tr>";
- $body .= "</table>";
- $this->corpo = $body;
- return $this->corpo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement