Emails con smtp phpmailer y servidores de gmail


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. if (!isset($_POST['email'])):
  4.  
  5. ?>
  6.  
  7.  
  8. <form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  9.  
  10. <p>
  11. <label>Nombre:<br />
  12. <input type="text" name="nombre" id="nombre" size="50"/>
  13. </label>
  14. </p>
  15. <p>
  16. <label>Apellido:<br />
  17. <input type="text" name="apellido" id="apellido" size="50"/>
  18. </label>
  19. </p>
  20.  
  21. <p>
  22. <label>Email:<br />
  23. <input type="text" name="email" id="email" size="50"/>
  24. </label>
  25. </p>
  26. <p>
  27. <label>Telefono:<br />
  28. <input type="text" name="tel" id="tel" size="50"/>
  29. </label>
  30. </p>
  31. <p>
  32. <label>Mensaje:<br />
  33. <textarea name="mensaje" id="mensaje" cols="45" rows="5"></textarea>
  34. </label>
  35. </p>
  36. <p>
  37. <label>
  38. <input type="submit" name="button" id="button" value="Enviar" />
  39. </label>
  40. </p>
  41. </form>
  42.  
  43.  
  44. <? else:
  45.  
  46.  
  47.  
  48. require_once 'class.phpmailer.php';
  49.  
  50. $mail = new PHPMailer ();
  51.  
  52.  
  53. $mail->IsSMTP();
  54. $mail->Host = 'ssl://smtp.gmail.com';
  55. $mail->Port = 465;
  56. $mail->SMTPAuth = true;
  57. $mail->Username = '[email protected]';
  58. $mail->Password = '*****';
  59.  
  60.  
  61.  
  62.  
  63. $mail -> From = $_POST[email];
  64. $mail -> FromName = $_POST[nombre];
  65. $mail -> AddAddress ("[email protected]");
  66. //$mail -> AddAddress ("[email protected]");
  67. $mail -> Subject = "Formulario de Contacto";
  68.  
  69. $body = "<strong>Nombre:</strong> $_POST[nombre] $_POST[apellido]<br>";
  70. $body .= "<strong>Email:</strong> $_POST[email]<br>";
  71. $body .= "<strong>Telefono:</strong> $_POST[tel]<br>";
  72. $body .= $_POST[mensaje];
  73. $mail->Body = $body;
  74. $mail->AltBody = "Mensaje:";
  75.  
  76.  
  77. $mail->AddReplyTo($_POST[email], $_POST[name]);
  78.  
  79.  
  80. $mail->Send();
  81.  
  82.  
  83.  
  84. echo"<p>Tu solicitud se envió con exito.</p>";
  85.  
  86. endif;
  87.  
  88. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.