Advertisement
Guest User

Untitled

a guest
Jan 4th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 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;
  58. date_default_timezone_set('Etc/UTC');
  59. $mail->isSMTP();
  60. $mail->Host = "smtp.gmail.com";
  61. $mail->SMTPDebug = 2;
  62. $mail->SMTPAuth = true;
  63. $mail->Username = 'privannn@gmail.com';
  64. $mail->Password = 'Makrill84';
  65. $mail->Port = 465;
  66. $mail->CharSet = "UTF-8";
  67. $mail->SMTPSecure = "ssl";
  68. $mail->IsHTML(true);
  69.  
  70.  
  71. $mail->From = $_POST["mail"];
  72. $mail->FromName = $_POST["namn"];
  73. $mail->AddAddress('privannn@gmail.com', 'Forsaken');
  74. $mail->addReplyTo($_POST["mail"], $_POST["namn"]);
  75. $mail->IsHTML(true);
  76. $mail->Subject = $_POST["amne"];
  77. $mail->Body = $_POST["message"];
  78. if (isset($_FILES['uploaded_file']) &&
  79. $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
  80. $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
  81. $_FILES['uploaded_file']['name']);
  82. }
  83.  
  84.  
  85.  
  86. $send = $mail->Send();
  87. if($send){
  88. echo 'Mail sent';
  89. }else{
  90. echo 'Mailer Error: ' . $mail->ErrorInfo;
  91.  
  92. }
  93. $name = '';
  94. $email = '';
  95. $subject = '';
  96. $message = '';
  97.  
  98.  
  99.  
  100. }
  101.  
  102.  
  103.  
  104. }
  105.  
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement