Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- $required = array('namn', 'mail', 'amne', 'message');
- $error = false;
- foreach($required as $field) {
- if (empty($_POST[$field])) {
- $error = true;
- }
- }
- if ($error) {
- echo "All fields are required.";
- } else {
- function post_captcha($user_response) {
- $fields_string = '';
- $fields = array(
- 'secret' => '6LeHUT4UAAAAAHnqaely7wGFV7wa-qk-Z93wb3X3',
- 'response' => $user_response
- );
- foreach($fields as $key=>$value)
- $fields_string .= $key . '=' . $value . '&';
- $fields_string = rtrim($fields_string, '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
- curl_setopt($ch, CURLOPT_POST, count($fields));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
- $result = curl_exec($ch);
- curl_close($ch);
- return json_decode($result, true);
- }
- $res = post_captcha($_POST['g-recaptcha-response']);
- if (!$res['success']) {
- echo '<p>Please check the reCaptcha</p>';
- } else {
- $subject = $_POST['amne'];
- $namn = $_POST['namn'];
- $message = $_POST['message'];
- $mail = $_POST['mail'];
- require 'mail/Exception.php';
- require 'mail/PHPMailer.php';
- require 'mail/SMTP.php';
- $mail = new PHPMailer;
- date_default_timezone_set('Etc/UTC');
- $mail->isSMTP();
- $mail->Host = "smtp.gmail.com";
- $mail->SMTPDebug = 2;
- $mail->SMTPAuth = true;
- $mail->Username = 'privannn@gmail.com';
- $mail->Password = 'Makrill84';
- $mail->Port = 465;
- $mail->CharSet = "UTF-8";
- $mail->SMTPSecure = "ssl";
- $mail->IsHTML(true);
- $mail->From = $_POST["mail"];
- $mail->FromName = $_POST["namn"];
- $mail->AddAddress('privannn@gmail.com', 'Forsaken');
- $mail->addReplyTo($_POST["mail"], $_POST["namn"]);
- $mail->IsHTML(true);
- $mail->Subject = $_POST["amne"];
- $mail->Body = $_POST["message"];
- if (isset($_FILES['uploaded_file']) &&
- $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
- $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
- $_FILES['uploaded_file']['name']);
- }
- $send = $mail->Send();
- if($send){
- echo 'Mail sent';
- }else{
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- }
- $name = '';
- $email = '';
- $subject = '';
- $message = '';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement