| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | $send_to = 'Website Enquiries <enquiries@' . preg_replace('/^www./', '', $_SERVER['HTTP_HOST']) . '>'; |
|---|
| 4 | |
|---|
| 5 | $emailfield = NULL; |
|---|
| 6 | $subjectfield = NULL; |
|---|
| 7 | $namefield = NULL; |
|---|
| 8 | |
|---|
| 9 | $when_done_goto = isset($_REQUEST['when_done_goto']) ? $_REQUEST['when_done_goto'] : NULL; |
|---|
| 10 | |
|---|
| 11 | if($_POST) |
|---|
| 12 | { |
|---|
| 13 | unset($_POST['when_done_goto']); |
|---|
| 14 | $message = ''; |
|---|
| 15 | $longestKey = 0; |
|---|
| 16 | foreach(array_keys($_POST) as $key) |
|---|
| 17 | { |
|---|
| 18 | $longestKey = max(strlen($key), $longestKey); |
|---|
| 19 | } |
|---|
| 20 | $longestKey = max($longestKey, 15); |
|---|
| 21 | |
|---|
| 22 | foreach($_POST as $Var => $Val) |
|---|
| 23 | { |
|---|
| 24 | if(!$emailfield) |
|---|
| 25 | { |
|---|
| 26 | if(preg_match('/(^|\s)e-?mail(\s|$)/i', $Var)) |
|---|
| 27 | { |
|---|
| 28 | $emailfield = $Var; |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | if(!$subjectfield) |
|---|
| 33 | { |
|---|
| 34 | if(preg_match('/(^|\s)subject(\s|$)/i', $Var)) |
|---|
| 35 | { |
|---|
| 36 | $subjectfield = $Var; |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | if(!$namefield) |
|---|
| 41 | { |
|---|
| 42 | if(preg_match('/(^|\s)from(\s|$)/i', $Var) || preg_match('/(^|\s)name(\s|$)/i', $Var)) |
|---|
| 43 | { |
|---|
| 44 | $namefield = $Var; |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | if(is_array($Val)) |
|---|
| 49 | { |
|---|
| 50 | $Val = implode(', ', $Val); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | $message .= $Var; |
|---|
| 54 | if(strlen($Var) < $longestKey) |
|---|
| 55 | { |
|---|
| 56 | $message .= str_repeat('.', $longestKey - strlen($Var)); |
|---|
| 57 | } |
|---|
| 58 | $message .= ':'; |
|---|
| 59 | if((64 - max(strlen($Var), $longestKey) < strlen($Val)) || preg_match('/\r?\n/', $Val)) |
|---|
| 60 | { |
|---|
| 61 | $message .= "\r\n "; |
|---|
| 62 | $message .= preg_replace('/\r?\n/', "\r\n ", wordwrap($Val, 62)); |
|---|
| 63 | } |
|---|
| 64 | else |
|---|
| 65 | { |
|---|
| 66 | $message .= ' ' . $Val . "\r\n"; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | $subject = $subjectfield ? $_POST[$subjectfield] : 'Enquiry'; |
|---|
| 71 | $email = $emailfield ? $_POST[$emailfield] : $send_to; |
|---|
| 72 | if($namefield) |
|---|
| 73 | { |
|---|
| 74 | $from = $_POST[$namefield] . ' <' . $email . '>'; |
|---|
| 75 | } |
|---|
| 76 | else |
|---|
| 77 | { |
|---|
| 78 | $from = 'Website Visitor' . ' <' . $email . '>'; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | mail($send_to, $subject, $message, "From: $from"); |
|---|
| 82 | |
|---|
| 83 | if(!$when_done_goto) |
|---|
| 84 | { |
|---|
| 85 | ?> |
|---|
| 86 | <html><head><title>Message Sent</title></head><body><h1>Message Sent</h1></body></html> |
|---|
| 87 | <?php |
|---|
| 88 | } |
|---|
| 89 | else |
|---|
| 90 | { |
|---|
| 91 | header("location: $when_done_goto"); |
|---|
| 92 | exit; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | ?> |
|---|