-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailTest.php
35 lines (33 loc) · 1009 Bytes
/
emailTest.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
<?php
function validare_email() {
if (!preg_match('/^[\w-.]+@[a-z-]+(\.[a-z-]+)+$/', $_POST['email']) ) {
return false;
}
return true;
}
if($_SERVER['REQUEST_METHOD'] === 'POST'){
session_start();
$emailErrors = array();
$emailSucces = 'OK';
if( !isset($_POST['message']) || !$_POST['message'] ){
$emailErrors[] = 'Please enter your message!';
$emailSucces = '';
}
if( !isset($_POST['name']) || !$_POST['name'] ){
$emailErrors[] = 'Please enter your name!';
$emailSucces = '';
}
if ( !isset($_POST['email']) || !$_POST['email'] ) {
$emailErrors[] = 'Please enter your email!';
$emailSucces = '';
} elseif (!validare_email()) {
$emailErrors[] = 'This email is invalid!';
$emailSucces = '';
}
if (empty($_SESSION['captcha']) || $_POST['captcha'] != $_SESSION['captcha']) {
$emailErrors[] = 'Invalid captcha';
$emailSucces = '';
}
header('Content-Type: application/json');
echo json_encode(array('emailErrors' => $emailErrors, 'emailSucces' => $emailSucces));
}