Advertisement
Guest User

Untitled

a guest
Apr 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. function envia_email($dest, $assunto, $nome_receptor, $template_path, $dados){
  2.  
  3.     $CI =& get_instance();
  4.  
  5.     $user = $CI->config->item('smtp_user');
  6.     $passwd = $CI->config->item('smtp_passwd');
  7.     $host = $CI->config->item('smtp_host');
  8.     $port = $CI->config->item('smtp_port');
  9.  
  10.  
  11.  
  12.     $tpl_path = FCPATH . 'templates/';
  13.  
  14.     $site_url = site_url();
  15.     $base_path = base_url();
  16.  
  17.     $template =  processa_template(
  18.         array('NOME' => $dados['nome'],
  19.               'URL' => $site_url,
  20.               'PATH' => $base_path
  21.              ),
  22.         'resposta_cadastro.php'
  23.     );
  24.  
  25.  
  26.     $mail = new PHPMailer(true);
  27.  
  28.  
  29.     // Passing `true` enables exceptions
  30.     try {
  31.         //Server settings
  32.         $mail->SMTPDebug = 0;                                 // Enable verbose debug output
  33.         $mail->isSMTP();                                      // Set mailer to use SMTP
  34.         $mail->Host = $host;  // Specify main and backup SMTP servers
  35.         $mail->SMTPAuth = true;                               // Enable SMTP authentication
  36.         $mail->Username = $user;                 // SMTP username
  37.         $mail->Password = $passwd;                           // SMTP password
  38.         $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
  39.         $mail->Port = 587;
  40.         $mail->CharSet = 'UTF-8';
  41.  
  42.         //Recipients
  43.         $mail->setFrom($user, $nome_receptor);
  44.         $mail->addAddress($dest, $dados['nome']);     // Add a recipient
  45.             // Name is optional
  46.  
  47.  
  48.  
  49.         //Content
  50.         $mail->isHTML(true);                                  // Set email format to HTML
  51.         $mail->Subject = $assunto;
  52.         $mail->Body    = $template;
  53.         //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  54.  
  55.         $mail->send();
  56.         return TRUE;
  57.     } catch (Exception $e) {
  58.         echo FALSE;
  59.     }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement