-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.php
76 lines (66 loc) · 2.99 KB
/
send.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
<?php
# EMAIL THE SUBMITTED FORM
function fcf_send() {
// send the email if the submit button is clicked
if ( isset( $_POST['fcf_submitted'] ) ) {
// make sure the user has filled in all the fields including the reCAPTCHA, otherwise, display a warning message
if ( !empty($_POST["fcf_contact_name"]) && !empty($_POST["fcf_contact_email"]) && !empty($_POST["fcf_contact_message"]) && !empty($_POST['g-recaptcha-response']) ) {
// secret key for reCAPTCHA
$secret = sanitize_text_field( get_option( 'fcf_recaptcha_secretkey' ) );
// verify reCAPTCHA response
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
// extract whether or not the reCAPTCHA response was successful
$responseData = json_decode($verifyResponse);
// get blog title to place in email
$blog_title = get_bloginfo( 'name' );
// sanitize form values and setup email message
$name = sanitize_text_field( $_POST["fcf_contact_name"] );
$phoneNumber = sanitize_text_field( $_POST["fcf_phone_number"] );
$email = sanitize_email( $_POST["fcf_contact_email"] );
$subject = "[$blog_title]" . " New Inquiry From $name";
// only place phone number in email if phone number field is active
global $displayTel;
if ( $displayTel == 1 ) {
global $message;
$message = "\nName: $name\n" . "\nPhone Number: $phoneNumber\n" . "\nEmail: $email\n" . "\nMessage:\n\n" . implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['fcf_contact_message'] ) ) );
} else {
global $message;
$message = "\nName: $name\n" . "\nEmail: $email\n" . "\nMessage:\n\n" . implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['fcf_contact_message'] ) ) );
}
// get the email address configured on the settings page, otherwise, fall back to the admin email address
if ( get_option( 'fcf_admin_email' ) ) {
$to = sanitize_email( get_option( 'fcf_admin_email' ) );
} else {
$to = sanitize_email( get_option( 'admin_email' ) );
}
// finally, attempt to send the email
if ( $responseData->success ) {
if ( wp_mail( $to, $subject, $message ) ) {
echo '<div class="fcf-card fcf-card-error">';
echo '<div class="fcf-card-text">';
echo 'Thanks for contacting us. We will respond to you as soon as possible.';
echo '</div>';
echo '</div>';
} else {
echo '<div class="fcf-card fcf-card-error">';
echo '<div class="fcf-card-text">';
echo 'Uh oh, something went wrong. Please check your entries and try again.';
echo '</div>';
echo '</div>';
}
} else {
echo '<div class="fcf-card fcf-card-error">';
echo '<div class="fcf-card-text">';
echo 'reCAPTCHA verification failed';
echo '</div>';
echo '</div>';
}
} else {
echo '<div class="fcf-card fcf-card-error">';
echo '<div class="fcf-card-text">';
echo 'Please fill out all the fields, including the reCAPTCHA.';
echo '</div>';
echo '</div>';
}
}
}