Advertisement
Guest User

Untitled

a guest
Jan 5th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. <?php
  2. use PHPMailer\PHPMailer\PHPMailer;
  3. use PHPMailer\PHPMailer\Exception;
  4.  
  5. $required = array('namn', 'mail', 'amne', 'message');
  6.  
  7.  
  8. $error = false;
  9. foreach($required as $field) {
  10. if (empty($_POST[$field])) {
  11. $error = true;
  12. }
  13. }
  14.  
  15. if ($error) {
  16. echo "All fields are required.";
  17. } else {
  18.  
  19.  
  20. function post_captcha($user_response) {
  21. $fields_string = '';
  22. $fields = array(
  23. 'secret' => '6LeHUT4UAAAAAHnqaely7wGFV7wa-qk-Z93wb3X3',
  24. 'response' => $user_response
  25. );
  26. foreach($fields as $key=>$value)
  27. $fields_string .= $key . '=' . $value . '&';
  28. $fields_string = rtrim($fields_string, '&');
  29.  
  30. $ch = curl_init();
  31. curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  32. curl_setopt($ch, CURLOPT_POST, count($fields));
  33. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  34. curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
  35.  
  36. $result = curl_exec($ch);
  37. curl_close($ch);
  38.  
  39. return json_decode($result, true);
  40. }
  41.  
  42.  
  43. $res = post_captcha($_POST['g-recaptcha-response']);
  44.  
  45. if (!$res['success']) {
  46.  
  47. echo '<p>Please check the reCaptcha</p>';
  48. } else {
  49. $subject = $_POST['amne'];
  50. $namn = $_POST['namn'];
  51. $message = $_POST['message'];
  52. $mail = $_POST['mail'];
  53.  
  54. require 'mail/Exception.php';
  55. require 'mail/PHPMailer.php';
  56. require 'mail/SMTP.php';
  57. $mail = new PHPMailer(true);
  58. date_default_timezone_set('Etc/UTC');
  59. $mail->isSMTP();
  60. $mail->Host = "smtp.gmail.com";
  61. $mail->SMTPAuth = true;
  62. $mail->Username = 'dinmail@gmail.com';
  63. $mail->Password = 'password';
  64. $mail->Port = 465;
  65. $mail->CharSet = "UTF-8";
  66. $mail->SMTPSecure = "ssl";
  67. $mail->IsHTML(true);
  68.  
  69.  
  70.  
  71.  
  72. $mail_body = "Message from {$_POST["namn"]} <br>";
  73. $mail_body .= "Query type: {$_POST["query"]} <br> \r\n";
  74. $mail_body .= "Message: {$_POST["message"]} <br> \r\n";
  75.  
  76.  
  77.  
  78. $mail->From = $_POST["mail"];
  79. $mail->FromName = $_POST["namn"];
  80. $mail->AddAddress('privannn@gmail.com', 'Forsaken');
  81. $mail->addReplyTo($_POST["mail"], $_POST["namn"]);
  82. $mail->Subject = $_POST["amne"];
  83. $mail->Body = $mail_body ;
  84. if (isset($_FIELS['fileToUpload']) &&
  85. $_FIELS['fileToUpload']['error'] == UPLOAD_ERR_OK) {
  86. $mail->AddAttachment($_FIELS['fileToUpload']['tmp_name'],
  87. $_FIELS['fileToUpload']['name']);
  88. }
  89.  
  90.  
  91.  
  92. $send = $mail->Send();
  93. if($send){
  94. echo 'Mail sent';
  95. var_dump($_FIELS);
  96. }else{
  97. echo 'Mailer Error: ' . $mail->ErrorInfo;
  98.  
  99. }
  100.  
  101. echo "<pr>"; print_r($_POST['uploaded_file']);echo "</pre>";
  102. $name = '';
  103. $email = '';
  104. $subject = '';
  105. $message = '';
  106.  
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113. }
  114.  
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement