diff --git a/composer.json b/composer.json index 12f8f70..7f039a7 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "catfan/medoo": "^1.5", "guzzlehttp/guzzle": "^6.2", "geoip2/geoip2": "~2.0", - "unsplash/unsplash": "^2.4" + "unsplash/unsplash": "^2.4", + "phpmailer/phpmailer": "^6.0" }, "license": "MPL-2.0", "authors": [ diff --git a/composer.lock b/composer.lock index c30be00..38f544f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "14eefa1d98fa62ca2f2fe52de606868c", - "content-hash": "e9f318b9d8bd1dfa6c7fb56c820d1910", + "hash": "f30e715ebe71e016a347feec9c9dc5bf", + "content-hash": "9efd5e7ff4f253d9ef07ae1535880ffb", "packages": [ { "name": "catfan/medoo", @@ -624,6 +624,72 @@ ], "time": "2018-04-04 21:24:14" }, + { + "name": "phpmailer/phpmailer", + "version": "v6.0.5", + "source": { + "type": "git", + "url": "https://github.com/PHPMailer/PHPMailer.git", + "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/cb3ea134d4d3729e7857737d5f320cce9caf4d32", + "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-filter": "*", + "php": ">=5.5.0" + }, + "require-dev": { + "doctrine/annotations": "1.2.*", + "friendsofphp/php-cs-fixer": "^2.2", + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "^4.8 || ^5.7", + "zendframework/zend-eventmanager": "3.0.*", + "zendframework/zend-i18n": "2.7.3", + "zendframework/zend-serializer": "2.7.*" + }, + "suggest": { + "ext-mbstring": "Needed to send email in multibyte encoding charset", + "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", + "league/oauth2-google": "Needed for Google XOAUTH2 authentication", + "psr/log": "For optional PSR-3 debug logging", + "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPMailer\\PHPMailer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, + { + "name": "Marcus Bointon", + "email": "phpmailer@synchromedia.co.uk" + }, + { + "name": "Andy Prevost", + "email": "codeworxtech@users.sourceforge.net" + }, + { + "name": "Brent R. Matzelle" + } + ], + "description": "PHPMailer is a full-featured email creation and transfer class for PHP", + "time": "2018-03-27 13:49:45" + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/lang/en_us.php b/lang/en_us.php index 99b75d8..a87fa4d 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -141,4 +141,6 @@ define("STRINGS", [ "new" => "New", "search" => "Search", "no results" => "No results.", + "contact form" => "Contact Form", + "contact form messages will be forwarded to this email address" => "Contact form messages will be forwarded to this email address, if it is set.", ]); diff --git a/pages/sitesettings.php b/pages/sitesettings.php index 49a0180..5f8fecb 100644 --- a/pages/sitesettings.php +++ b/pages/sitesettings.php @@ -245,6 +245,20 @@ function getsetting($name) { + +
+
+
+
+
+ +
+ " /> +
+ +
+
+
diff --git a/public/contact.php b/public/contact.php index 074fd1b..93b6856 100644 --- a/public/contact.php +++ b/public/contact.php @@ -4,9 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +ignore_user_abort(true); require __DIR__ . "/../lib/requiredpublic.php"; +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\Exception; + function output_card($content) { ?> @@ -33,8 +37,10 @@ END; die(); } +$siteid = getsiteid(); + $database->insert("messages", [ - "siteid" => getsiteid(), + "siteid" => $siteid, "name" => htmlspecialchars($_POST['name']), "email" => htmlspecialchars($_POST['email']), "message" => htmlspecialchars($_POST['message']), @@ -47,4 +53,36 @@ $content = <<Continue END; -output_card($content); \ No newline at end of file +output_card($content); +ob_flush(); +flush(); + + +if ($database->has('settings', ["AND" => ['siteid' => $siteid, 'key' => 'contactemail']])) { + $emailto = $database->get('settings', "value", ["AND" => ['siteid' => $siteid, 'key' => 'contactemail']]); + // Setup mailer + $mail = new PHPMailer(true); + $mail->isSMTP(); + $mail->Host = SMTP_HOST; + $mail->SMTPAuth = SMTP_AUTH; + if (SMTP_AUTH) { + $mail->Username = SMTP_USERNAME; + $mail->Password = SMTP_PASSWORD; + } + if (SMTP_SECURITY != "none") { + $mail->SMTPSecure = SMTP_SECURITY; + } + $mail->Port = SMTP_PORT; + $mail->isHTML(true); + $mail->setFrom(SMTP_FROMADDRESS, SMTP_FROMNAME); + + $mail->addAddress($emailto); + $mail->addReplyTo($_POST['email'], $_POST['name']); + + $mail->Subject = 'Website Contact Form Message'; + $mail->Body = '

From: ' . htmlspecialchars($_POST['name']) . ' <' . $_POST['email'] . '>

' + . '

Message:
' . htmlspecialchars($_POST['message']) . '

'; + $mail->AltBody = "From: $_POST[name] <$_POST[email]>\r\n\r\nMessage: \r\n$_POST[message]"; + + $mail->send(); +} \ No newline at end of file diff --git a/settings.template.php b/settings.template.php index 3a29ab4..64fcd5b 100644 --- a/settings.template.php +++ b/settings.template.php @@ -20,6 +20,14 @@ define("DB_CHARSET", "utf8"); // Name of the app. define("SITE_TITLE", "SiteWriter"); +define("SMTP_HOST", ""); +define("SMTP_AUTH", true); +define("SMTP_SECURITY", "tls"); // tls, ssl, or none +define("SMTP_PORT", 25); +define("SMTP_USERNAME", ""); +define("SMTP_PASSWORD", ""); +define("SMTP_FROMADDRESS", "sitewriter@example.com"); +define("SMTP_FROMNAME", "SiteWriter"); // URL of the AccountHub API endpoint define("PORTAL_API", "http://localhost/accounthub/api.php");