X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/dc7b531b3d4c33d18f64396ca20b0e010579cc88..3671d53f7cdf7bfbf628d7d5adbb2e2847450fb9:/widget/contact.php?ds=sidebyside
diff --git a/widget/contact.php b/widget/contact.php
index a4fccda..8fdc948 100644
--- a/widget/contact.php
+++ b/widget/contact.php
@@ -1,25 +1,28 @@
login) {
- $_REQUEST['login'] = $User->login;
- $_REQUEST['email'] = $_REQUEST['email'] ?: $User->email;
- }
- else {
- unset($_REQUEST['login']);
- }
- $error = mailform($_REQUEST);
- if (!empty($error)) {
- print "
$error
\n\n";
- }
+global $User;
+if ($User->login) {
+ $_REQUEST['login'] = $User->login;
+ $_REQUEST['email'] = $_REQUEST['email'] ?: $User->email;
+}
+else {
+ unset($_REQUEST['login']);
+}
+$error = mailform($_REQUEST, $Page->place);
+if (!empty($error)) {
+ print "$error
\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 +42,6 @@ switch ($source) {
if (empty($input['naam']) or empty($input['huis'])) {
return 'De bedoeling is juist dat je opgeeft wie er komt.';
}
- $rcpt .= ', Heleen ';
break;
default:
if (empty($input['email']) or !preg_match('/.+@.+\..+/', $input['email'])) {
@@ -52,8 +54,18 @@ switch ($source) {
$reply = preg_match('/\A[^\s\'@]{1,64}@[.a-zA-Z0-9-]{4,63}\z/', @$input['email'])
? $input['email'] : "noreply@$domain";
+ if ($displayname = @$input['naam']) {
+ $reply = sprintf('"%s" <%s>', addcslashes($displayname, "\\\"\0..\37"), $reply);
+ }
$header = "From: $reply";
+ if ($origin = @$_SERVER['REMOTE_ADDR']) {
+ if ($resolved = @gethostbyaddr($origin) and $resolved !== $origin) {
+ $origin .= sprintf(' (%s)', gethostbyaddr($origin));
+ }
+ $header .= "\r\nReceived: from $origin by $domain{$config['url']}; ".date('r');
+ }
+
foreach (array(
'X-Accept-Language' => 'HTTP_ACCEPT_LANGUAGE',
'User-Agent' => 'HTTP_USER_AGENT',
@@ -62,16 +74,17 @@ switch ($source) {
$header .= "\r\n$mailhdr: ".$_SERVER[$serverhdr];
}
- $origin = $_SERVER['REMOTE_ADDR'];
- if ($resolved = @gethostbyaddr($origin) and $resolved !== $origin) {
- $origin .= sprintf(' (%s)', gethostbyaddr($origin));
- }
- $body = "Ingevuld vanaf $origin:\r\n\r\n";
-
+ $body = '';
foreach ($input as $k => $v) {
$body .= "$k: $v\r\n";
}
+ if ($logfile = fopen('maillog.txt', 'a')) {
+ $logdata = "Date: ".strftime("%F %T");
+ $logdata .= "\nTo: $rcpt\nSubject: $subject\n$header\n\n$body.\n\n";
+ fwrite($logfile, str_replace("\r\n", "\n", $logdata));
+ }
+
$sent = mail($rcpt, $subject, $body, $header);
if (!$sent)
return 'Helaas ging er iets mis bij het doorvoeren. Probeer het later nog eens.';