JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
first stab at paypal_ipn framework
[wfpl-cms.git] / contact.php
1 <?php
2
3 # This form requires wfpl. See: http://sametwice.com/wfpl
4
5 # SETUP
6
7 # To send results by e-mail, all you have to do is set your e-mail address here:
8 $GLOBALS['contact_form_recipient'] = 'fixme@example.com';
9 $GLOBALS['contact_robot_answer'] = 1002;
10
11
12 require_once(DOCROOT . 'inc/wfpl/format.php');
13 require_once(DOCROOT . 'inc/wfpl/email.php');
14
15 function contact_get_fields() {
16         $data = array();
17
18         $data['name'] = format_oneline(_REQUEST_cut('name'));
19         $data['email'] = format_email(_REQUEST_cut('email'));
20         $data['robot'] = format_oneline(_REQUEST_cut('robot'));
21         $data['comments'] = format_unix(_REQUEST_cut('comments'));
22
23         return $data;
24 }
25
26
27 function contact_main() {
28         return contact_main_form();
29 }
30
31 function contact_main_form($id = false) {
32         $robot_correct = "" . $GLOBALS['contact_robot_answer'];
33         $robot_minus_one = "" . ($GLOBALS['contact_robot_answer'] - 1);
34         $robot_plus_one = "" . ($GLOBALS['contact_robot_answer'] + 1);
35         tem_set('robot_minus_one', $robot_minus_one);
36         tem_set('robot_plus_one', $robot_plus_one);
37
38         if(isset($_POST['name'])) {
39                 $data = contact_get_fields();
40                 $host = this_host();
41
42                 if(!$data['name'] && !$data['email'] && !$data['comments']) {
43                         // message("you didn't fill anything out")
44                 } elseif($data['robot'] !== $robot_correct) {
45                         message("Please type $robot_correct into the Robot Barrier field");
46                 } else {
47                         if($GLOBALS['contact_form_recipient'] != 'fixme@example.com') {
48                                 $to = $GLOBALS['contact_form_recipient'];
49                                 $from = "$host/contact <noreply@cmstest.com>";
50                                 $reply_to = $to;
51                                 if(isset($data['email']) and valid_email($data['email'])) {
52                                         $reply_to = $data['email'];
53                                         if($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
54                                                 $reply_to = "$data[name] <$reply_to>";
55                                         }
56                                 }
57                                 $subject = "Your message via $host/contact";
58                                 $email_template = new tem();
59                                 $email_template->load('contact.email.txt');
60                                 $email_template->sets($data);
61                                 $email_template->set('$host', $host);
62                                 $message = $email_template->run();
63                                 $cc = '';
64                                 $bcc = '';
65                                 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
66                                         message('Due to an internal error, your message could not be sent. Please try again later.');
67                                         $error = true;
68                                 } else {
69                                         message('Message sent');
70                                 }
71                         }
72                         if($error !== true) {
73                                 # FIXME create this page or change this to go elsewhere
74                                 return './contact_thanks';
75                         }
76                 }
77                 # otherwise, we display the form again. We've got the form field
78                 # values in $data and will put those back in the filds below. You
79                 # should add some message asking people to fix their entry in
80                 # whatever way you require.
81         } else {
82                 # form not submitted, you can set default values like so:
83                 #$data = array('name' => 'Yes');
84                 $data = array();
85         }
86
87         tem_set('form', $data);
88 }