widget/contact: subject and recipient address from call options
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 25 Jan 2021 22:55:24 +0000 (23:55 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 26 Jan 2021 00:23:36 +0000 (01:23 +0100)
Custom variables instead of hardcoding each case.

widget/contact.php

index c6e702234b8d8d00e46258d6c5952a75f0108ac2..6ccb79a987bf0cff58d1ffbb62c382ada2708b30 100644 (file)
@@ -9,17 +9,18 @@ if ($_POST) {
        else {
                unset($_REQUEST['login']);
        }
-       $error = mailform($_REQUEST);
+       $error = mailform($_REQUEST, $Page->place);
        if (!empty($error)) {
                print "<p class=warn>$error</p>\n\n";
        }
 }
 
-function mailform($input = [])
+function mailform($input = [], $config = [])
 {
-       $source = empty($input['subject']) ? 'reactie' : $input['subject'];
+       $source = $config['subject'] ??
+               (empty($input['subject']) ? 'reactie' : $input['subject']);
        $domain = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
-       $rcpt = "info@$domain";
+       $rcpt = $config['rcpt'] ?? "info@$domain";
        $subject = "Formulier {$_SERVER['HTTP_HOST']}: $source";
 
        if (!$input) {
@@ -39,7 +40,6 @@ switch ($source) {
                if (empty($input['naam']) or empty($input['huis'])) {
                        return 'De bedoeling is juist dat je opgeeft wie er komt.';
                }
-               $rcpt .= ', Heleen <heleen.terlouw.2910@gmail.com>';
                break;
        default:
        if (empty($input['email']) or !preg_match('/.+@.+\..+/', $input['email'])) {