|
1 <?php |
|
2 //If the form is submitted |
|
3 if(isset($_POST['submitted'])) { |
|
4 |
|
5 // require a name from user |
|
6 if(trim($_POST['contactName']) == '') { |
|
7 $nameError = 'Forgot your name!'; |
|
8 $hasError = true; |
|
9 } else { |
|
10 $name = trim($_POST['contactName']); |
|
11 } |
|
12 |
|
13 // need valid email |
|
14 if(trim($_POST['email']) == '') { |
|
15 $emailError = 'Forgot to enter in your e-mail address.'; |
|
16 $hasError = true; |
|
17 } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { |
|
18 $emailError = 'You entered an invalid email address.'; |
|
19 $hasError = true; |
|
20 } else { |
|
21 $email = trim($_POST['email']); |
|
22 } |
|
23 |
|
24 // we need at least some content |
|
25 if(trim($_POST['comments']) == '') { |
|
26 $commentError = 'You forgot to enter a message!'; |
|
27 $hasError = true; |
|
28 } else { |
|
29 if(function_exists('stripslashes')) { |
|
30 $comments = stripslashes(trim($_POST['comments'])); |
|
31 } else { |
|
32 $comments = trim($_POST['comments']); |
|
33 } |
|
34 } |
|
35 |
|
36 // upon no failure errors let's email now! |
|
37 if(!isset($hasError)) { |
|
38 |
|
39 $emailTo=''; |
|
40 if ( function_exists( 'get_option_tree') ){ |
|
41 if( get_option_tree( 'contact_page_email') ) { |
|
42 $emailTo = get_option_tree( 'contact_page_email' ); |
|
43 |
|
44 } |
|
45 } |
|
46 $body = "Name: $name \n\nEmail: $email \n\nComments: $comments"; |
|
47 $headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; |
|
48 mail($emailTo, $headers, $body); |
|
49 $emailSent = true; |
|
50 } |
|
51 } |
|
52 ?> |