-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.php
88 lines (64 loc) · 2.23 KB
/
process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require 'recaptcha.php';
use Phelium\Component\reCAPTCHA;
require 'mail/class.smtp.php';
require 'mail/class.phpmailer.php';
ini_set('display_errors', 1);
error_reporting(E_ALL);
$reCAPTCHA = new reCAPTCHA('PUBLIC_KEY', 'SECRET_KEY');
$errors = array();
$data = array();
/* NAME */
if (empty($_POST["name"])) {
$errors['name'] = "Name is required";
}
/* EMAIL */
if (empty($_POST["email"])) {
$errors['email'] = "Email is required";
} else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$errors['email'] = "Invalid email format";
}
/* MSG SUBJECT */
if (empty($_POST["msg_subject"])) {
$errors['msg_subject'] = "Subject is required";
}
/* MESSAGE */
if (empty($_POST["msg_text"])) {
$errors['msg_text'] = "Message is required";
}
if ( !$reCAPTCHA->isValid($_POST['grecaptcha']))
{
$errors['grecaptcha'] = 'Please try again. We are unable to send your form.';
}
$msg = "Name: ".$_POST["name"].", Email: ".$_POST["email"].", Subject: ".$_POST["msg_subject"].", Message:".$_POST["msg_text"];
if(!empty($errors)) {
$data['success'] = false;
$data['errors'] = $errors;
$data['message'] = 'There was an error with your form. Please Review.';
} else {
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->Host = "SERVER";
$mail->SMTPAuth = true;
$mail->Username = "SMTP_USERNAME";
$mail->Password = "SMTP_PASSWORD";
$mail->SMTPSecure = 'DEFINE EITHER TLS OR SSL';
$mail->Port = "DEFINE PORT NUMBER AS A NUMBER NOT STRING";
$mail->From = "FROM_EMAIL"; //<-- do not fake
$mail->FromName = 'FROM NAME';
$mail->AddAddress('ADDRESS_TO_SEND_TO');
$mail->AddReplyTo($_POST["email"]); //optional
$mail->IsHTML(false); //disable for plain text or true if you want to render html
$mail->Subject = $_POST['msg_subject'];
$mail->Body = $msg;
if(!$mail->Send()) {
$data['success'] = false;
$data['message'] = 'There were errors with your form, please refer to the warnings!';
} else {
$data['success'] = true;
$data['message'] = 'Success! Your message was sent. I will contact you shortly.';
}
}
echo json_encode($data);
?>