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