fixed some bugs on prod server regarding paths; config and sqlite files now reside one directory above webroot
This commit is contained in:
parent
a22afad927
commit
900f1f0a63
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
||||
|
||||
require(dirname(__FILE__) . '/../functions.php');
|
||||
$webroot = $_SERVER['DOCUMENT_ROOT'];
|
||||
require($webroot . '/functions.php');
|
||||
|
||||
$successURL = '/newsletter/danke.html';
|
||||
$errorURL = '/error.html';
|
||||
|
||||
@ -7,7 +7,8 @@ if ( $_POST['address'] != '' ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
require(dirname(__FILE__) . '/../functions.php');
|
||||
$webroot = $_SERVER['DOCUMENT_ROOT'];
|
||||
require($webroot . '/functions.php');
|
||||
|
||||
$successURL = '/success.html';
|
||||
$errorURL = '/error.html';
|
||||
@ -23,12 +24,12 @@ $body = [
|
||||
$mailContents = [
|
||||
'subject' => 'Diese Nachricht kam ueber das Kontaktformular von t-r.de',
|
||||
'bodyText' => implode("\n\n", $body),
|
||||
'fromAddress' => '***REMOVED***', //'kontakt@tobias-radloff.de',
|
||||
'fromAddress' => $general['notificationAddress'],
|
||||
'fromName' => 'Tobias Radloffs Kontaktformular'
|
||||
];
|
||||
|
||||
try {
|
||||
SendEmail($_POST['email'], $mailContents);
|
||||
SendEmail($general['notificationAddress'], $mailContents);
|
||||
} catch (Exception $e) {
|
||||
GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
|
||||
}
|
||||
|
||||
@ -9,30 +9,21 @@ require $dname . '/Exception.php';
|
||||
require $dname . '/PHPMailer.php';
|
||||
require $dname . '/SMTP.php';
|
||||
|
||||
$webroot = $_SERVER['DOCUMENT_ROOT'];
|
||||
|
||||
// read ini file
|
||||
$ini_file = '../../config.ini';
|
||||
$ini_file = $webroot . '/../config.ini';
|
||||
$ini = parse_ini_file($ini_file, TRUE);
|
||||
|
||||
// general constants
|
||||
$general = [
|
||||
// string concatenated with email address to create a non-recreatable md5 hash
|
||||
'uniqueKey' => $ini['hash']['uniqueKey'], // works like password salt
|
||||
// file name of confirm script
|
||||
'confirmScript' => '/newsletter/confirm.php',
|
||||
// status code to be used when redirection to success or error page
|
||||
'statusCode' => 'HTTP/1.1 303 See Other',
|
||||
// array of SQL statements used
|
||||
'sql' => [
|
||||
'create_table' => 'CREATE TABLE IF NOT EXISTS subscribers (id INTEGER PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT);',
|
||||
'create_record' => 'INSERT INTO subscribers(email, name) VALUES(:e, :n);',
|
||||
'read_record' => 'SELECT 1 FROM subscribers WHERE email = :e;',
|
||||
'update_record' => '',
|
||||
'delete_record' => 'DELETE FROM subscribers WHERE email = :e;'
|
||||
],
|
||||
'notificationAddress' => 'webseite@tobias-radloff.de'
|
||||
$general = $ini['general'];
|
||||
$general['sql'] = [
|
||||
'create_table' => 'CREATE TABLE IF NOT EXISTS subscribers (id INTEGER PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT);',
|
||||
'create_record' => 'INSERT INTO subscribers(email, name) VALUES(:e, :n);',
|
||||
'read_record' => 'SELECT 1 FROM subscribers WHERE email = :e;',
|
||||
'update_record' => '',
|
||||
'delete_record' => 'DELETE FROM subscribers WHERE email = :e;'
|
||||
];
|
||||
// complete site URL
|
||||
$general['siteURL'] = $ini['general']['protocol'] . '://' . $ini['general']['domain'];
|
||||
|
||||
$smtp = $ini['smtp'];
|
||||
$db = $ini['db'];
|
||||
@ -45,7 +36,14 @@ function GetConfirmationHash($confEmail) {
|
||||
// connects to database and returns PDO object
|
||||
function getPDO($dbType = 'sqlite') {
|
||||
global $db;
|
||||
return new \PDO($db[$dbType]['dsn']);
|
||||
if ( $dbType == 'sqlite' ) {
|
||||
global $webroot;
|
||||
error_log('my dsn is ' . 'sqlite:' . $webroot . '/../' . $db['sqlite_file']);
|
||||
|
||||
return new \PDO('sqlite:' . $webroot . '/../' . $db['sqlite_file']);
|
||||
}
|
||||
// error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Sends an email to single recipient with subject, body and sender info specified in an array
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
<?php
|
||||
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
||||
|
||||
require(dirname(__FILE__) . '/../functions.php');
|
||||
$webroot = $_SERVER['DOCUMENT_ROOT'];
|
||||
require($webroot . '/functions.php');
|
||||
|
||||
$successURL = '/success.html';
|
||||
$errorURL = '/error.html';
|
||||
$err = 'Anmeldung fehlgeschlagen';
|
||||
|
||||
// file name of confirm script
|
||||
$confirmScript = '/newsletter/confirm.php';
|
||||
|
||||
|
||||
// body template for confirmation email
|
||||
$body = [
|
||||
'Hallo!',
|
||||
@ -47,7 +52,7 @@ try {
|
||||
|
||||
// build and add link to
|
||||
$confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]);
|
||||
$confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery;
|
||||
$confirmLink = $general['site_url'] . $confirmScript . "?" . $confirmQuery;
|
||||
$mailContents['bodyHTML'] = str_replace('%Placeholder%', "<a href=\"{$confirmLink}\">Anmeldung bestätigen</a>", $mailContents['bodyHTML']);
|
||||
$mailContents['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyText']);
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require(dirname(__FILE__) . '/../functions.php');
|
||||
$webroot = $_SERVER['DOCUMENT_ROOT'];
|
||||
require($webroot . '/functions.php');
|
||||
|
||||
$successURL = '/success.html';
|
||||
$errorURL = '/error.html';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user