· 7 years ago · Jan 07, 2019, 10:54 AM
1<?php
2 $msg = "";
3 use PHPMailer\PHPMailer\PHPMailer;
4 use PHPMailer\PHPMailer\Exception;
5
6 include_once "phpmailer/PHPMailer.php";
7 include_once "phpmailer/Exception.php";
8 include_once "phpmailer/SMTP.php";
9
10 if (isset($_POST['submit'])) {
11 $subject = $_POST['subject'];
12 $email = $_POST['email'];
13 $message = $_POST['message'];
14 $name = $_POST['name'];
15
16 $recaptcha = false;
17 $secretKey = '6LeL4IQUAAAAALHlV2EIQNBkPN9qrKcyAl3Ja1u5';
18 $responseKey = $_POST['g-recaptcha-response'];
19 $userIP = $_SERVER['REMOTE_ADDR'];
20 $url = 'https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP';
21 $response = file_get_contents($url);
22 $response = json_decode($response);
23
24 if ($response->success) {
25 $recaptcha = true;
26 echo 'Verification success.';
27 }
28 else {
29 echo 'Verification failed.';
30 }
31
32 $mail = new PHPMailer();
33
34 //if we want to send via SMTP
35 //$mail->Host = "smtp.tiscali.it";
36 //$mail->isSMTP();
37 //$mail->SMTPAuth = true;
38 //$mail->Username = "davidemarca@tiscali.it";
39 //$mail->Password = "Davide1983";
40 //$mail->SMTPSecure = "ssl"; //TLS
41 //$mail->Port = 465; //587
42
43 if ($recaptcha)
44 $mail->addAddress('davidemarca@tiscali.it');
45 $mail->setFrom($email);
46 $mail->Subject = $subject;
47 $mail->isHTML(true);
48 $mail->Body = $message;
49
50 if ($mail->send())
51 $msg = "<p style='color: green; font-style: italic; font-weight: bold;'>Email inviata con successo!</p>";
52 else
53 $msg = "<p style='color: red; font-style: italic; font-weight: bold;'>Si è verificato un errore. Riprova più tardi.</p>";
54 }
55?>
56
57<!DOCTYPE html>
58<html lang="it">
59<head>
60<meta charset="utf-8">
61<title></title>
62</head>
63<body>
64<form>
65<div class="g-recaptcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxx"></div>
66</form>
67
68<script src='https://www.google.com/recaptcha/api.js'></script>
69</body>
70</html>