· 4 years ago · Mar 02, 2021, 10:40 PM
1 require 'recaptcha/autoload.php';
2
3 $secret = $secret_key;
4 $response = null;
5
6
7 $reCaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
8 if ($_POST["g-recaptcha-response"]){
9
10 $response = $reCaptcha->verify(
11 $_POST["g-recaptcha-response"],
12 $_SERVER["REMOTE_ADDR"]
13 );
14
15 if ($response != null && $response->isSuccess()){
16
17 require 'gump.class.php';
18 $gump = new GUMP();
19 $validated = $gump->validate($_POST,$rules);
20
21 if($validated === TRUE){
22
23 require 'class.phpmailer.php';
24
25 $form = $_POST;
26 $mail = new PHPMailer;
27 $mail->setFrom($from, $from_name);
28 $recipient_array = explode(',', $recipient);
29
30 foreach ($recipient_array as $individual_recipient){
31 $mail->addAddress($individual_recipient);
32 }
33
34 $mail->addReplyTo($form['email']);
35
36 if($cc !== ''){
37 $cc_array = explode(',', $cc);
38 foreach ($cc_array as $individual_cc){
39 $mail->addCC($individual_cc);
40 }
41 }
42 if($bcc !== ''){
43 $bcc_array = explode(',', $bcc);
44 foreach ($bcc_array as $individual_bcc){
45 $mail->addBCC($individual_bcc);
46 }
47 }
48
49 $mail->isHTML(true);
50
51 if(isset($form['subject'])){
52 $mail->Subject = $form['subject'];
53 }
54 else{
55 $mail->Subject = $subject;
56 }
57
58 $mail->Body = '<html><head><style>table{border-collapse: collapse;max-width:100%}td{border:none;padding:5px;vertical-align:top}</style></head><body><table>';
59
60 foreach($form as $name => $value){
61 if($name != "g-recaptcha-response" && $name != 'ctc-filename'){
62 $real_value = $value;
63 if(is_array($value)){
64 $real_value = "";
65 foreach ($value as $val){
66 $real_value = $real_value.$val."<br>";
67 }
68 }
69
70 $mail->Body .= '<tr><td style="text-align:right;font-weight:700">'.ucwords(str_replace("_"," ",$name)).':</td><td>'.$real_value.'</td></tr>';
71 }
72 }
73
74 $mail->Body .= '</table></body></html>';
75 $mail->AltBody = "";
76
77 foreach($form as $name => $value){
78 if ($name != 'ctc-filename') {
79 $mail->AltBody .=ucwords(str_replace("_"," ",$name)).":".$value."\r\n";
80 }
81 }
82
83 if(!$mail->send()) {
84 echo 'not-sent';
85 }
86 else{
87 if($form['email']){
88 $mail->clearAllRecipients();
89 $mail->Subject = "Thank you";
90 $mail->Body = "<p>Thank you for your message. This is to confirm that you have sent the following information below.</p>".$mail->Body;
91 $mail->addAddress($form['email']);
92 $mail->send();
93 }
94
95 unset($_POST);
96
97 echo 'sent';
98
99 }
100
101 } else{
102 $return_error = array();
103 foreach($validated as $key=>$error){
104 $return_error[] = array('name'=>$error['field'],'msg'=>$error_texts["{$error['field']}"]);
105 }
106 echo json_encode($return_error);
107 }
108
109 } else {
110 echo "wrong-recaptcha";
111 }
112 }
113
114 else {
115 echo "no-recaptcha";
116 }