Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('class.phpmailer.php');
  4. require_once('class.smtp.php');
  5. require_once('PHPMailerAutoload.php');
  6.  
  7. require('vistas/mail.view.php');
  8.  
  9.  
  10. define("destino", "correo@gmail.com");
  11. define("farmacia", "Guillermo");
  12.  
  13. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  14. $nombre=filter_var($_POST['nombre'], FILTER_SANITIZE_STRING);
  15. $de=filter_var($_POST['de'], FILTER_SANITIZE_EMAIL);
  16. $telefono=filter_var($_POST['telefono'], FILTER_SANITIZE_STRING);
  17. $asunto=filter_var($_POST['asunto'], FILTER_SANITIZE_STRING);
  18. $mensaje='
  19. <!DOCTYPE html>
  20. <html lang="en">
  21. <head>
  22. <meta charset="UTF-8">
  23. <title>Document</title>
  24. </head>
  25. <body>
  26. <h1>Cuerpo del mensaje</h1>
  27. <table border="1">
  28. <tr>
  29. <td>Uno</td>
  30. <td>Dos</td>
  31. </tr>
  32. </table>
  33. </body>
  34. </html>
  35. ';
  36. $mensaje.=filter_var($_POST['mensaje'], FILTER_SANITIZE_STRING);
  37.  
  38.  
  39. $correo = new PHPMailer(); //Creamos una instancia en lugar usar mail()
  40.  
  41. $correo->IsSMTP();
  42. $correo->SMTPOptions = array('ssl' => array('verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true));
  43.  
  44. // optional
  45. // used only when SMTP requires authentication
  46. $correo->SMTPAuth = true;
  47. $correo->SMTPSecure = 'tls';
  48. $correo->Host = 'smtp.gmail.com';
  49. $correo->Port = 587;
  50. $correo->Username = 'correo@gmail.com';
  51. $correo->Password = 'password';
  52.  
  53. //Usamos el SetFrom para decirle al script quien envia el correo
  54. $correo->SetFrom($de, $nombre);
  55.  
  56. //Usamos el AddReplyTo para decirle al script a quien tiene que responder el correo
  57. $correo->AddReplyTo($de, $nombre);
  58.  
  59. //Usamos el AddAddress para agregar un destinatario
  60. $correo->AddAddress(destino, farmacia);
  61.  
  62. //Ponemos el asunto del mensaje
  63. $correo->Subject = $asunto;
  64.  
  65. /*
  66. * Si deseamos enviar un correo con formato HTML utilizaremos MsgHTML:
  67. * $correo->MsgHTML("<strong>Mi Mensaje en HTML</strong>");
  68. * Si deseamos enviarlo en texto plano, haremos lo siguiente:
  69. * $correo->IsHTML(false);
  70. * $correo->Body = "Mi mensaje en Texto Plano";
  71. */
  72. $correo->MsgHTML($mensaje);
  73.  
  74.  
  75.  
  76. //Si deseamos agregar un archivo adjunto utilizamos AddAttachment
  77. //$correo->AddAttachment("images/phpmailer.gif");
  78. $correo->CharSet = "UTF­8";
  79. //$correo->Encoding = "quoted­printable";
  80.  
  81. //Enviamos el correo
  82. if(!$correo->Send()) {
  83. echo "Hubo un error: " . $correo->ErrorInfo;
  84. } else {
  85. echo "Mensaje enviado con exito.";
  86. }
  87.  
  88. }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement