Guest User

Untitled

a guest
Oct 27th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. <?php
  2. require 'PHPMailer/src/Exception.php';
  3. require 'PHPMailer/src/PHPMailer.php';
  4. require 'PHPMailer/src/SMTP.php';
  5.  
  6. //HTML Form Removel
  7. function removeHTML($texttovalid){
  8. $texttovalid = trim($texttovalid);
  9. if(strlen($texttovalid)>0){
  10. $texttovalid = htmlspecialchars(stripslashes($texttovalid));
  11. }
  12. return $texttovalid;
  13. }
  14.  
  15.  
  16. //Form POST variables
  17. $nome = removeHTML($_POST['nome']);
  18. $email = removeHTML($_POST['email']);
  19. $msg ='';
  20.  
  21. // Begining of validating variables
  22. if(isset($_POST['submit']))
  23. {
  24. $required = array("nome", "email");
  25. foreach($_POST as $key=>$value)
  26. {
  27. if (empty($value) && in_array($key, $required) === true)
  28. {
  29. $msg = 'Fill in required fields.';
  30. break 1;
  31. }
  32. if (!filter_var($email, FILTER_VALIDATE_EMAIL))
  33. {
  34. $msg = 'Invalid email';
  35. }
  36. }
  37. if (empty($msg) === true) {
  38.  
  39. $body = "rNome: $nome";
  40. $body .= "rnE-mail: $email";
  41.  
  42. $bodysend = utf8_decode($body);
  43.  
  44.  
  45. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  46. try {
  47. //Server settings
  48. $mail->SMTPDebug = 1;
  49. $mail->isSMTP(); // Set mailer to use SMTP
  50. $mail->Host = 'mail.dfg.pt'; // Specify main and backup SMTP servers
  51. $mail->SMTPAuth = true; // Enable SMTP authentication
  52. $mail->Username = 'geral@xxx.com'; // SMTP username
  53. $mail->Password = 'xxxxxx'; // SMTP password
  54. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  55. $mail->Port = 587; // TCP port to connect to
  56. $mail->setLanguage('pt', 'PHPMailer/language/');
  57.  
  58. //Recipients
  59. $mail->setFrom('geral@xxx.com', 'DFG');
  60. $mail->addAddress($email, $nome); // Add a recipient
  61. $mail->addBCC('info@xxx.com');
  62.  
  63. //Content
  64. $mail->isHTML(true); // Set email format to HTML
  65. $mail->Subject = 'This is a subject';
  66. $mail->Body = $bodysend;
  67.  
  68. $mail->send();
  69. $msg = 'Thank you.';
  70. } catch (Exception $e) {
  71. $msg = 'Error occurred. Mailer Error: '. $mail->ErrorInfo;
  72. }
  73.  
  74. }
  75.  
  76. } ?>
  77.  
  78. <div class="alert-msg"><?php echo $msg;?></div>
  79. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
  80. <div class="mt-10">
  81. <input type="text" name="nome" placeholder="Nome" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Nome'" class="single-input">
  82. </div>
  83. <div class="mt-10">
  84. <input type="email" name="email" placeholder="E-mail" onfocus="this.placeholder = ''" onblur="this.placeholder = 'E-mail'" required class="single-input">
  85. </div>
  86. <div class="mt-10">
  87. <button type="submit" class="primary-btn hover submit-btn d-inline-flex align-items-center mt-20"><span class="mr-10">Submit</span><span class="lnr lnr-arrow-right"></span></button>
  88. </div>
  89. </form>
  90.  
  91. PHP Notice: Undefined index: nome in /public_html/index.php on line 17
  92. [27-Oct-2018 14:13:57 UTC]
  93. PHP Notice: Undefined index: email in /public_html/index.php on line 18
Add Comment
Please, Sign In to add comment