Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / php-mailer / mail.php
1 <?
2 $date_full = date("d M Y, H:i:s");
3 $date = date("d.m.y");
4 $ip = getenv('REMOTE_ADDR');
5 $ip_proxy = getenv('HTTP_X_FORWARDED_FOR');
6 $host = gethostbyaddr($ip);
7
8 $name=$_POST['name'];
9 $email=$_POST['email'];
10 $comments = ($_POST['comments']) ? stripslashes($_POST['comments']) : '';
11 $nopreview= (int)$_POST['nopreview'];
12
13 $to="contact@grml.org";
14 $subject="grml contact web";
15
16 function checkname($name) {
17         $filter  = "/^([a-zA-ZöäüÖÄÜß0-9_\.\-\+\ ])+$/";
18         return preg_match($filter,$name);
19 }
20
21 function checkmail($email) {
22         $filter  = "/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/";
23         return preg_match($filter,$email);
24 }
25
26 function badwords($text) {
27         $spamfilter = array('viagra','sex ', 'phentermine','free time', 'you may find', 'interesting', 'good site', 'keep alive', 'webmaster', 'web-master', 'great web', 'casino', 'isurance', 'buy', 'porn', 'loan', 'pharmacy', 'closeup', 'goodlife', 'multipart', 'zion', 'jude', 'ausländer', 'content-type', 'url=', 'asphost4free.com', 'hostrator.com');
28
29         $text = strtolower($text);
30         foreach($spamfilter as $word) {
31                 $pos = strpos($text, $word);
32                 if ($pos !== false) {
33                         return true;
34                 }
35         }
36         return false;
37 }
38
39
40 // validation
41
42 $error = null;
43
44 if(!checkname($name)){
45   $error =  "Sorry, this does not seem to be a valid name.";
46 }
47
48 if(empty($email)){
49         $error = "Sorry, without your email address we won't be able to contact you. ;-)";
50 }
51
52 if (!checkmail($email)) {
53         $error = "Sorry, no valid email address found.";
54 }
55
56 if(empty($comments)){
57         $error = "Empty message - we don't like empty messages. ;-)";
58 }
59
60 if(badwords($comments)){
61         $error = "We don't accept spam messages.";
62 }
63
64 if ($error) $nopreview = 1;
65
66 // send mail
67
68 if (($nopreview == 1) && !$error) {
69
70         // mailheader
71
72         $xtra    = "From: ($name) $email\r\n";
73         $xtra   .= "Content-Type: text/plain; charset=ISO-8859-15\nContent-Transfer-Encoding: 8bit\r\n";
74         $xtra   .= "X-Mailer: PHP ". phpversion();
75
76         // mailbody
77
78         $message="Message:\n\n$comments\n\n\nLoggin-Information:\n-------------------\nName:   $name\nE-Mail: $email\nDate:   $date_full\nIP:     $ip\nIP-Proxy:  $ip_proxy\nHost:   $host\n";
79
80         if(mail($to,$subject,$message,$xtra)) {
81                 $mailsent = "Sending the message was <b>successful</b>. Thanks for your message.";
82         } else {
83                 $error = "An error occured while sending mail. Sorry :-(";
84         }
85 }
86 ?>