Config\maxDailyEmails()) { $msg = "$name <$email> requested an OTP email, but $countEmailsSentLast24Hours emails have already been sent, whereas the max daily load is " . Config\maxDailyEmails() . "."; syslog(LOG_WARNING, $msg); http_response_code(500); echo $msg; exit(); } } function getNameFromPayloadAndValidate(array $payload): string { $name = (string) $payload["name"]; if (is_null($name) || $name == "") { http_response_code(400); echo "name must not be empty"; exit(); } return $name; } function getEmailFromPayloadAndValidate(array $payload): string { $email = (string) $payload["email"]; if (is_null($email) || $email == "") { http_response_code(400); echo "email must not be empty"; exit(); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { http_response_code(400); echo "<$email> is not a valid email address."; exit(); } return $email; } function getTypeFromPayloadAndValidate(array $payload): string { $type = (string) $payload["type"]; if (!in_array($type, SEND_OTP_TYPES)) { http_response_code(400); echo "type must be one of: " . SEND_OTP_TYPES; exit(); } return $type; }