Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Nestor Blanco
Added: Jun 8, 2018 6:21 PM
Views: 21
Tags: no tags
  1. <?php
  2.  
  3. date_default_timezone_set('America/Caracas');
  4.  
  5. require 'lib/PHPMailer-master/src/PHPMailer.php';
  6. require 'lib/PHPMailer-master/src/SMTP.php';
  7. require 'lib/PHPMailer-master/src/Exception.php';
  8.  
  9. $name = $_POST['name'];
  10. $email  = $_POST['email'];
  11. $message  = $_POST['message'];
  12.  
  13. //echo "tu name es: ".$name."</br>";
  14. //echo "email es: ".$email."</br>";;
  15. //echo "message es: ".$message."</br>";
  16. //echo ("Fecha: ".$name." | Nombre: ".$name);
  17. if($name=="" || $email=="" || $message == "")
  18. {
  19.     echo '<script>alert("Complete the required fields");</script>';
  20. }else{
  21.  
  22.  
  23. //Create a new PHPMailer instance
  24. //$mail = new PHPMailer;
  25.  
  26. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  27. //$mail = new PHPMailer(true);
  28.  
  29. //Tell PHPMailer to use SMTP
  30. //$mail->isSendMail(); //or $mail->isSMTP();
  31. $mail->isSMTP();//or $mail->isSendMail();
  32.  
  33. //Enable SMTP debugging
  34. // 0 = off (for production use)
  35. // 1 = client messages
  36. // 2 = client and server messages
  37. $mail->SMTPDebug = 2;
  38.  
  39. $mail->Timeout=60;
  40.  
  41. $mail->Helo = "dominio.com"; //Muy importante para que llegue a hotmail y otros
  42.  
  43. //Set the hostname of the mail server
  44. $mail->Host = 'smtp.gmail.com';
  45.  
  46. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  47. $mail->Port = 587;
  48.  
  49. //Set the encryption system to use - ssl (deprecated) or tls
  50. $mail->SMTPSecure = 'tls';
  51.  
  52. //Whether to use SMTP authentication
  53. $mail->SMTPAuth = true;
  54.  
  55. //Username to use for SMTP authentication - use full email address for gmail
  56. $mail->Username = "interlux.ve@gmail.com";
  57.  
  58. //Password to use for SMTP authentication
  59. $mail->Password = "J302876516";
  60.  
  61. //Set who the message is to be sent from
  62. $mail->setFrom(''.$email.'', ''.$name.'');
  63.  
  64. //Set an alternative reply-to address
  65. $mail->addReplyTo(''.$email.'', ''.$name.'');
  66.  
  67. //Set who the message is to be sent to
  68. $mail->addAddress(''.$email.'');
  69.  
  70. //Set the subject line
  71. $mail->Subject = ''.$email.'';
  72.  
  73. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  74.  
  75. $mail->Body = '<h1>'.$message.'</h1>';
  76.  
  77. $mail->IsHTML(true);
  78.  
  79. //send the message, check for errors
  80. if (!$mail->send()) {
  81.     //echo "Mailer Error: " . $mail->ErrorInfo;
  82.     echo '<script>alert("Mailer Error:'.$mail->ErrorInfo.'");</script>';
  83. } else {
  84.     //echo "Message sent: ".$message;
  85.     echo '<script>alert("Message sent...");</script>';
  86. }
  87.  
  88. }
  89.  
  90. ?>