-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendmail.php
More file actions
57 lines (53 loc) · 1.83 KB
/
Copy pathsendmail.php
File metadata and controls
57 lines (53 loc) · 1.83 KB
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
<?php
require_once('config.php');
require_once('recaptcha/recaptchalib.php');
$json = array();
$email = isset( $_POST['email'] ) ? $_POST['email'] : '';
$name = isset( $_POST['name'] ) ? $_POST['name'] : '';
$message = isset( $_POST['message'] ) ? $_POST['message'] : '';
if( !$name ) {
$json['error']['name'] = 'Please enter your full name.';
}
if( !$message ) {
$json['error']['message'] = 'Please enter your message.';
}
if( !$email || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email ) ) {
$json['error']['email'] = 'Please enter your email address.';
}
// Checking reCaptcha
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]
);
// if reCaptcha is invalid
if (!$resp->is_valid) {
# set the error code so that we can display it
$error = $resp->error;
$json['error']['recaptcha'] = 'Incorrect code. Please try again.';
}
} else {
$json['error']['recaptcha'] = 'Please enter the text from reCaptcha.';
}
$json['recaptcha'] = recaptcha_get_html( $publickey, $error );
// If no errors
if( !isset( $json['error'] ) ) {
// Email text
$mail_message = "From: " . $name . "\r\n\r\n";
$mail_message .= "E-mail: " . $email . "\r\n\r\n";
$mail_message .= "Message:\r\n\r\n" . $message . "";
// Email title
$mail_headers = "Content-type: text/plain; charset=utf-8\r\n";
$mail_headers .= "From: {$mail_sender}\r\n";
// Sending email
mail( $to_email, $mail_subject, $mail_message, $mail_headers );
$json['success'] = 'Your message was sent successfully!';
}
echo json_encode( $json );
?>