Guest User

Untitled

a guest
Jan 12th, 2018
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?php
  2. $nome = $_POST["nome"];
  3. $email = $_POST["email"];
  4. $assunto = $_POST["assunto"];
  5. $msg = $_POST["msg"];
  6.  
  7. // Import PHPMailer classes into the global namespace
  8. // These must be at the top of your script, not inside a function
  9. use PHPMailerPHPMailerPHPMailer;
  10. use PHPMailerPHPMailerException;
  11.  
  12. //Load composer's autoloader
  13. require '../phpmailer/vendor/autoload.php';
  14.  
  15. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  16.  
  17. try {
  18. //Server settings
  19. $mail->SMTPDebug = 2; // Enable verbose debug output
  20. $mail->isSMTP(); // Set mailer to use SMTP
  21. $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
  22. $mail->SMTPAuth = true; // Enable SMTP authentication
  23. $mail->Username = 'meuEmail@gmail.com'; // SMTP username
  24. $mail->Password = 'minhaSenha'; // SMTP password
  25. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  26. $mail->Port = 587; // TCP port to connect to
  27.  
  28. //Define o remetente
  29. $mail->setFrom($email, $nome);
  30.  
  31. //Define o destinatário
  32. $mail->addAddress('meuEmail@gmail.com'); // Add a recipient
  33.  
  34. //Content
  35. $mail->isHTML(true); // Set email format to HTML
  36. $mail->Subject = $assunto;
  37. $mail->Body = '<html>De: '.$nome.'<br/>Email:'.$email.'<br/>Assunto:'.$assunto.'Mensagem: '.$msg.'</html>';
  38. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  39.  
  40. $mail->send();
  41. echo 'Message has been sent';
  42. } catch (Exception $e) {
  43. echo 'Message could not be sent.';
  44. echo 'Mailer Error: ' . $mail->ErrorInfo;
  45. }
Add Comment
Please, Sign In to add comment