Add support for email notification for contact form messages, close #29

master
Skylar Ittner 6 vuotta sitten
vanhempi 7bf050d730
commit 9887a96c74

@ -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": [

70
composer.lock generated

@ -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",

@ -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.",
]);

@ -245,6 +245,20 @@ function getsetting($name) {
</div>
</div>
<!-- Contact Form -->
<div class="card mt-4">
<div class="card-body">
<h5 class="card-title"><i class="fas fa-comments"></i> <?php lang("contact form"); ?></h5>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><label for="contactemail"><i class="fas fa-envelope"></i> Forward to:</label></span>
</div>
<input type="email" class="form-control" name="settings[contactemail]" id="contactemail" value="<?php echo getsetting("contactemail"); ?>" />
</div>
<small class="form-text"><?php lang("contact form messages will be forwarded to this email address"); ?></small>
</div>
</div>
<!-- Extra code header snippets -->
<div class="card mt-4 mb-4">
<div class="card-body">

@ -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) {
?>
<!DOCTYPE html>
@ -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 = <<<END
<a href="./" class="btn btn-success">Continue</a>
END;
output_card($content);
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 = '<p><b>From:</b> ' . htmlspecialchars($_POST['name']) . ' &lt;<a href="mailto:' . htmlspecialchars($_POST['email']) . '">' . $_POST['email'] . '</a>&gt;</p>'
. '<p><b>Message:</b> <br>' . htmlspecialchars($_POST['message']) . '</p>';
$mail->AltBody = "From: $_POST[name] <$_POST[email]>\r\n\r\nMessage: \r\n$_POST[message]";
$mail->send();
}

@ -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");

Ladataan…
Peruuta
Tallenna