Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1.     public function smtpMailer($para, $de, $de_nome, $assunto, $corpo)
  2.     {
  3.         $path = __DIR__.'/../../view/mail/'.$corpo.'.html';
  4.         if (file_exists($path)) {
  5.             $arquivo = file_get_contents($path);
  6.             global $error;
  7.             $mail = new PHPMailer();
  8.             $mail->IsSMTP();        // Ativar SMTP
  9.             $mail->SMTPDebug = 0;       // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
  10.             $mail->SMTPAuth = true;     // Autenticação ativada
  11.             $mail->SMTPSecure = 'ssl';  // SSL REQUERIDO pelo GMail
  12.             $mail->Host = 'smtp.gmail.com'; // SMTP utilizado
  13.             $mail->Port = 465;          // A porta 587 deverá estar aberta em seu servidor
  14.             $mail->Username = '';
  15.             $mail->Password = '';
  16.             $mail->SetFrom($de, $de_nome);
  17.             $mail->Subject = utf8_decode($assunto);
  18.             $mail->Body = utf8_decode($arquivo);
  19.             $mail->IsHTML(true);
  20.             $mail->AddAddress($para);
  21.             if (!$mail->Send()) {
  22.                 $error = 'Mail error: '.$mail->ErrorInfo;
  23.  
  24.                 return false;
  25.             } else {
  26.                 $error = 'Mensagem enviada!';
  27.  
  28.                 return true;
  29.             }
  30.         } else {
  31.             $error = 'Arquivo não encotrado';
  32.  
  33.             return false;
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement