Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2.  
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. use PHPMailer\PHPMailer\Exception;
  5.  
  6. require("vendor/autoload.php");
  7.  
  8.  
  9. define('SMTP_USER', '****');
  10. define('SMTP_PASS', '****');
  11. define('SMTP_HOST', ****);
  12. define('SMTP_PORT', 587);
  13.  
  14. class Mail{
  15.  
  16.  
  17. function send($para, $de, $de_nome, $assunto, $corpo) {
  18. $mail = new PHPMailer();
  19. $mail->IsSMTP(); // Ativar SMTP
  20. $mail->SMTPDebug = 0; // Debug: 1 = erros e mensagens, 2 = mensagens apenas
  21. $mail->SMTPAuth = true; // Autenticação
  22. $mail->SMTPSecure = 'tsl'; // SSL Ou TSL
  23.  
  24. $mail->Host = SMTP_HOST; // Servidor SMTP utilizado
  25. $mail->Port = SMTP_PORT; // A porta habilitada no servidor
  26. $mail->Username = SMTP_USER;
  27. $mail->Password = SMTP_PASS;
  28.  
  29. //Variáveis da mensagem, remetente, assunto, mensagem e destinatário.
  30. $mail->SetFrom($de, $de_nome);
  31. $mail->Subject = $assunto;
  32. $mail->Body = $corpo;
  33. $mail->AddAddress($para);
  34.  
  35. if(!$mail->Send()) {
  36. return ['status' => false, 'message' => 'Mensagem não enviada: '.$mail->ErrorInfo];
  37. } else {
  38. return ['status' => true, 'message' => 'Mensagem enviada com sucesso!'];
  39. }
  40. }
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement