Merge branch 'allow-smtp-config' into 'develop'
Allow setting SMTP config Closes #192 and #150 See merge request framasoft/framadate!224
This commit is contained in:
commit
129dcba693
@ -42,7 +42,7 @@ $is_admin = false;
|
||||
$logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$inputService = new InputService();
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$notificationService = new NotificationService($mailService);
|
||||
$securityService = new SecurityService();
|
||||
|
||||
|
@ -28,7 +28,7 @@ include_once __DIR__ . '/../app/inc/init.php';
|
||||
|
||||
$logService = new LogService();
|
||||
$sessionService = new SessionService();
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$pollService = new PollService($connect, $logService);
|
||||
|
||||
$result = false;
|
||||
@ -91,4 +91,4 @@ $smarty->error_reporting = E_ALL & ~E_NOTICE;
|
||||
|
||||
$response = ['result' => $result, 'message' => $message];
|
||||
|
||||
echo json_encode($response);
|
||||
echo json_encode($response);
|
||||
|
@ -49,7 +49,7 @@ $logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$adminPollService = new AdminPollService($connect, $pollService, $logService);
|
||||
$inputService = new InputService();
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$notificationService = new NotificationService($mailService);
|
||||
|
||||
/* PAGE */
|
||||
|
@ -10,21 +10,26 @@ class MailService {
|
||||
|
||||
private $smtp_allowed;
|
||||
|
||||
private $smtp_options = [];
|
||||
|
||||
private $logService;
|
||||
|
||||
function __construct($smtp_allowed) {
|
||||
function __construct($smtp_allowed, $smtp_options = []) {
|
||||
$this->logService = new LogService();
|
||||
$this->smtp_allowed = $smtp_allowed;
|
||||
if (true === is_array($smtp_options)) {
|
||||
$this->smtp_options = $smtp_options;
|
||||
}
|
||||
}
|
||||
|
||||
public function isValidEmail($email) {
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
function send($to, $subject, $body, $msgKey = null) {
|
||||
public function send($to, $subject, $body, $msgKey = null) {
|
||||
if ($this->smtp_allowed === true && $this->canSendMsg($msgKey)) {
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->isSMTP();
|
||||
$this->configureMailer($mail);
|
||||
|
||||
// From
|
||||
$mail->FromName = NOMAPPLICATION;
|
||||
@ -60,7 +65,7 @@ class MailService {
|
||||
}
|
||||
}
|
||||
|
||||
function canSendMsg($msgKey) {
|
||||
public function canSendMsg($msgKey) {
|
||||
if ($msgKey === null) {
|
||||
return true;
|
||||
}
|
||||
@ -70,5 +75,28 @@ class MailService {
|
||||
}
|
||||
return !isset($_SESSION[self::MAILSERVICE_KEY][$msgKey]) || time() - $_SESSION[self::MAILSERVICE_KEY][$msgKey] > self::DELAY_BEFORE_RESEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the mailer with the options
|
||||
*
|
||||
* @param PHPMailer $mailer
|
||||
*/
|
||||
private function configureMailer(PHPMailer $mailer) {
|
||||
$mailer->isSMTP();
|
||||
|
||||
$available_options = [
|
||||
'host' => 'Host',
|
||||
'auth' => 'SMTPAuth',
|
||||
'username' => 'Username',
|
||||
'password' => 'Password',
|
||||
'secure' => 'SMTPSecure',
|
||||
'port' => 'Port',
|
||||
];
|
||||
|
||||
foreach ($available_options as $config_option => $mailer_option) {
|
||||
if (true === isset($this->smtp_options[$config_option]) && false === empty($this->smtp_options[$config_option])) {
|
||||
$mailer->{$mailer_option} = $this->smtp_options[$config_option];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,14 @@ const TIME_EDIT_LINK_EMAIL = 60;
|
||||
$config = [
|
||||
/* general config */
|
||||
'use_smtp' => true, // use email for polls creation/modification/responses notification
|
||||
'smtp_options' => [
|
||||
'host' => 'localhost', // SMTP server (you could add many servers (main and backup for example) : use ";" like separator
|
||||
'auth' => false, // Enable SMTP authentication
|
||||
'username' => '', // SMTP username
|
||||
'password' => '', // SMTP password
|
||||
'secure' => '', // Enable encryption (false, tls or ssl)
|
||||
'port' => 25, // TCP port to connect to
|
||||
],
|
||||
'tracking_code' => '', // add HTML code to every page, useful for tools like Piwik
|
||||
/* home */
|
||||
'show_what_is_that' => true, // display "how to use" section
|
||||
@ -98,5 +106,5 @@ $config = [
|
||||
'default_poll_duration' => 180, // default values for the new poll duration (number of days).
|
||||
/* create_classic_poll.php */
|
||||
'user_can_add_img_or_link' => true, // user can add link or URL when creating his poll.
|
||||
'markdown_editor_by_default' => true // The markdown editor for the description is enabled by default
|
||||
'markdown_editor_by_default' => true, // The markdown editor for the description is enabled by default
|
||||
];
|
||||
|
@ -29,7 +29,7 @@ include_once __DIR__ . '/app/inc/init.php';
|
||||
/*---------*/
|
||||
$logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$purgeService = new PurgeService($connect, $logService);
|
||||
|
||||
if (is_file('bandeaux_local.php')) {
|
||||
@ -44,7 +44,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
|
||||
$smarty->assign('error', __('Error', 'You haven\'t filled the first section of the poll creation.'));
|
||||
$smarty->display('error.tpl');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Min/Max archive date
|
||||
$min_expiry_time = $pollService->minExpiryDate();
|
||||
$max_expiry_time = $pollService->maxExpiryDate();
|
||||
|
@ -30,7 +30,7 @@ include_once __DIR__ . '/app/inc/init.php';
|
||||
/*---------*/
|
||||
$logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$purgeService = new PurgeService($connect, $logService);
|
||||
$inputService = new InputService();
|
||||
|
||||
|
@ -4,16 +4,16 @@
|
||||
* is not distributed with this file, you can obtain one at
|
||||
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
|
||||
*
|
||||
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
||||
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
||||
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
||||
*
|
||||
* =============================
|
||||
*
|
||||
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
||||
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
||||
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
||||
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
||||
*
|
||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||
*/
|
||||
|
||||
@ -28,7 +28,7 @@ include_once __DIR__ . '/app/inc/init.php';
|
||||
/* -------- */
|
||||
$logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
|
||||
/* PAGE */
|
||||
/* ---- */
|
||||
|
@ -57,7 +57,7 @@ $comments = [];
|
||||
$logService = new LogService();
|
||||
$pollService = new PollService($connect, $logService);
|
||||
$inputService = new InputService();
|
||||
$mailService = new MailService($config['use_smtp']);
|
||||
$mailService = new MailService($config['use_smtp'], $config['smtp_options']);
|
||||
$notificationService = new NotificationService($mailService);
|
||||
$securityService = new SecurityService();
|
||||
$sessionService = new SessionService();
|
||||
|
Loading…
Reference in New Issue
Block a user