Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2.  
  3. $txtName = "Bruno";
  4. $txtAs = "As";
  5. $txtEmail = "Text mail";
  6. $txtMensage = "Text Body";
  7. $mensageBody = "<b>Name:</b> ".$txtName." <br><b>As:</b> ".$txtAs."<br><b>Message:</b> ".$txtMensage;
  8.  
  9. require 'phpmailer/PHPMailerAutoload.php';
  10. require 'phpmailer/class.smtp.php';
  11.  
  12. function smtpmailer($to, $from, $nameDes, $as, $body) {
  13. global $error;
  14. $mail = new PHPMailer();
  15.  
  16. $mail->IsSMTP();
  17. $mail->SMTPDebug = 2;
  18. $mail->SMTPSecure = 'tls';
  19. $mail->Host = 'smtp.gmail.com';
  20. $mail->Port = 587;
  21. $mail->SMTPAuth = true;
  22. $mail->SMTPSecure = true;
  23. $mail->Username = 'mail@gmail.com';
  24. $mail->Password = 'pass';
  25. $mail->SetFrom($from, $nameDes);
  26. $mail->Subject = $as;
  27. $mail->Body = $body;
  28. $mail->AddAddress($to);
  29. $mail->IsHTML(true);
  30.  
  31. if(!$mail->Send()) {
  32. $error = "<font color='red'><b>Mail error: </b></font>".$mail->ErrorInfo;
  33. return false;
  34. } else {
  35. $error = "<font color='blue'><b>Mensagem enviada com Sucesso!</b></font>";
  36. return true;
  37. }
  38. }
  39.  
  40. if (smtpmailer('mail@gmail.com', 'mail@gmail.com', $txtName, $txtAs, $mensageBody)) {
  41. Header("location: sucesso.php");
  42. }
  43. if (!empty($error)) echo $error;
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement