Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. $nome = $_POST["nome"];
  5. $email = $_POST["email"];
  6. $mensagem = $_POST["mensagem"];
  7.  
  8. require_once("PHPMailer.php");
  9. require_once 'OAuth.php';
  10. require_once 'POP3.php';
  11. require_once 'SMTP.php';
  12. require_once 'Exception.php';
  13. use PHPMailer\PHPMailer\PHPMailer;
  14. use PHPMailer\PHPMailer\Exception;
  15.  
  16. $mail = new PHPMailer();
  17.  
  18. $mail->isSMTP();
  19. $mail->Host = 'smtp.gmail.com';
  20. $mail->Port = 587;
  21. $mail->SMTPSecure = 'tls';
  22. $mail->SMTPAuth = true;
  23. $mail->Username = "jhenifer.msantos@gmail.com";
  24. $mail->Password = "";
  25.  
  26. #quem estΓ‘ mandando email
  27. $mail->setFrom("alura.php.e.mysql@gmail.com", "Alura Curso PHP e MySQL");
  28.  
  29. #quem esta recebendo o email
  30. $mail->addAddress("jhenifer.msantos@gmail.com");
  31.  
  32. #assunto da mensagem
  33. $mail->Subject = "Email de contato da loja";
  34.  
  35. #mensagem como HTML
  36. $mail->msgHTML("<html>de: {$nome}<br/>email: {$email}<br/>mensagem: {$mensagem}</html>");
  37.  
  38. #mensagem como TXT
  39. $mail->AltBody = "de: {$nome}\nemail:{$email}\nmensagem: {$mensagem}";
  40.  
  41. $mail->SMTPOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
  42.  
  43. if($mail->send()){
  44.     $_SESSION["success"] = "Mensagem enviada com sucesso";
  45.     header("Location: index.php");
  46. } else {
  47.     $_SESSION["danger"] = "Erro ao enviar mensagem " . $mail->ErrorInfo;
  48.     header("Location: contato.php");
  49. }
  50. die();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement