3 # This form requires wfpl. See: http://sametwice.com/wfpl
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'] = '';
14 require_once(__DIR__.'/'.'inc/wfpl/format.php');
15 require_once(__DIR__.'/'.'inc/wfpl/email.php');
17 # generate a new random 16-character string
18 function contact_new_field_key() {
19 $character_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
22 # PHP 4.2.0 and up seed the random number generator for you.
23 # Lets hope that it seeds with something harder to guess than the clock.
24 for($i = 0; $i < 16; ++$i) {
25 $id{$i} = $character_set{mt_rand(0, 61)};
31 function contact_get_fields() {
35 $data['name'] = format_oneline(_REQUEST_cut('name'));
36 $data['comments'] = format_unix(_REQUEST_cut('comments'));
38 $fields = _REQUEST_cut('fields');
39 if (preg_match('/^[a-zA-Z0-9]{32}$/', $fields)) {
40 $data['robot'] = format_oneline(_REQUEST_cut(substr($fields, 0, 16)));
41 $data['email'] = format_email(_REQUEST_cut(substr($fields, 16)));
48 function contact_main() {
49 return contact_main_form();
52 function contact_main_form() {
53 if (isset($_POST['name'])) {
54 $data = contact_get_fields();
57 # gj robot, you did it ;)
58 if ($data['robot'] !== '') {
59 return './contact_thanks';
62 if (!$data['name'] && !$data['email'] && !$data['comments']) {
63 // message("you didn't fill anything out")
64 } elseif (!$data['email']) {
65 message("Error: Please fill out the email field.");
68 if ($data['robot'] === '' && $GLOBALS['contact_to'] != 'fixme@example.com') {
69 $to = $GLOBALS['contact_to'];
70 if ($GLOBALS['contact_from'] === '') {
71 $from = "$host/contact <noreply@$host>";
73 $from = $GLOBALS['contact_from'];
76 if (isset($data['email']) and valid_email($data['email'])) {
77 $reply_to = $data['email'];
78 if ($data['name'] and preg_match('/^[a-zA-Z0-9_\'. -]*$/', $data['name']) !== false) {
79 $reply_to = "$data[name] <$reply_to>";
82 if ($GLOBALS['contact_subject'] === '') {
83 $subject = "Your message via $host/contact";
85 $subject = $GLOBALS['contact_subject'];
87 $email_template = new tem();
88 $email_template->load('contact.email.txt');
89 $email_template->sets($data);
90 $email_template->set('$host', $host);
91 $message = $email_template->run();
92 $cc = $GLOBALS['contact_cc'];
94 if (email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
95 message('Due to an internal error, your message could not be sent. Please try again later.');
98 message('Message sent');
101 if ($error !== true) {
102 # FIXME create this page or change this to go elsewhere
103 return './contact_thanks';
106 # otherwise, we display the form again. We've got the form field
107 # values in $data and will put those back in the filds below. You
108 # should add some message asking people to fix their entry in
109 # whatever way you require.
111 # form not submitted, you can set default values like so:
112 #$data = array('name' => 'Yes');
116 $data['robot_field'] = contact_new_field_key();
117 $data['email_field'] = contact_new_field_key();
119 tem_set('form', $data);