d0fcc50f68cc40582b80c8a3a5b501f3edbdcdba
[mtweb] / web / app / mods / forms / contact.php
1 <?php
2
3   if(file_exists($this->path("libs")."ptitcaptcha.php")) require $this->path("libs")."ptitcaptcha.php";
4
5   class mw_forms_contact extends mw_mod
6   {
7
8     function validate(&$env)
9     { if($pages_view_mod = $env->get_mod("pages/view"))
10       { return $pages_view_mod->validate(&$env);
11       }
12       return true;
13     }
14
15     function index(&$env)
16     { if($env->config("contact_form") && $env->config("email"))
17       { if($_POST)
18         { if
19           ( $this->send
20             ( $env,
21               $_POST["email"],
22               "[".$env->config("site_name")."] nouveau message",
23               $_POST["message"],
24               $env->config("email"),
25               $env->config("captcha")
26             )
27           )
28           { $env->redirect
29             ( $env->url("index"),
30               "Le message a &eacute;t&eacute; envoy&eacute;",
31               2
32             );
33           }
34         }
35       }
36       else $env->run("index");
37     }
38
39     function send(&$env, $from, $titre, $message, $dest, $captcha)
40     { $env->set_out("ENVOYE", false);
41       if($captcha && !file_exists($env->path("libs")."ptitcaptcha.php"))
42       { $env->erreur("fichier du captcha introuvable");
43         return false;
44       }
45       if(!$captcha || PtitCaptchaHelper::checkCaptcha())
46       { if($from)
47         { if($dest)
48           { if
49             ( mail
50               ( $dest,
51                 $titre,
52                 $message,
53                  "From: ".$from."\r\n"
54                 ."Reply-To: ".$from."\r\n"
55               )
56             )
57             { $env->set_out("ENVOYE", true);
58               return true;
59             }
60             else $env->erreur("Erreur &agrave; l'envoi du mail");
61           }
62           else $env->erreur("Impossible de trouver l'email du destinataire");
63         }
64         else $env->message("merci de pr&eacute;ciser un email");
65       }
66       else $env->message("anti-spam incorrect");
67       return false;
68     }
69
70   }
71
72 ?>