diff --git a/action/add_comment.php b/action/add_comment.php index df75385..d4247eb 100644 --- a/action/add_comment.php +++ b/action/add_comment.php @@ -42,7 +42,7 @@ $is_admin = false; $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $notificationService = new NotificationService($mailService); $securityService = new SecurityService(); diff --git a/action/send_edit_link_by_email_action.php b/action/send_edit_link_by_email_action.php index a2ac204..1097e7a 100644 --- a/action/send_edit_link_by_email_action.php +++ b/action/send_edit_link_by_email_action.php @@ -28,7 +28,7 @@ include_once __DIR__ . '/../app/inc/init.php'; $logService = new LogService(); $sessionService = new SessionService(); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $pollService = new PollService($connect, $logService); $result = false; diff --git a/adminstuds.php b/adminstuds.php index f4e472e..407e23d 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -50,7 +50,7 @@ $logService = new LogService(); $pollService = new PollService($connect, $logService); $adminPollService = new AdminPollService($connect, $pollService, $logService); $inputService = new InputService(); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $notificationService = new NotificationService($mailService); $sessionService = new SessionService(); diff --git a/app/classes/Framadate/Services/MailService.php b/app/classes/Framadate/Services/MailService.php index 9c32f3f..fdc58d9 100644 --- a/app/classes/Framadate/Services/MailService.php +++ b/app/classes/Framadate/Services/MailService.php @@ -8,18 +8,39 @@ class MailService { const MAILSERVICE_KEY = 'mailservice'; + /** + * @var bool + */ private $smtp_allowed; + /** + * @var array + */ private $smtp_options = []; + /** + * @var bool + */ + private $use_sendmail; + + /** + * @var LogService + */ private $logService; - function __construct($smtp_allowed, $smtp_options = []) { + /** + * MailService constructor. + * @param $smtp_allowed + * @param array $smtp_options + * @param bool $use_sendmail + */ + public function __construct($smtp_allowed, $smtp_options = [], $use_sendmail = false) { $this->logService = new LogService(); $this->smtp_allowed = $smtp_allowed; if (true === is_array($smtp_options)) { $this->smtp_options = $smtp_options; } + $this->use_sendmail = $use_sendmail; } public function isValidEmail($email) { @@ -82,7 +103,11 @@ class MailService { * @param PHPMailer $mailer */ private function configureMailer(PHPMailer $mailer) { - $mailer->isSMTP(); + if ($this->use_sendmail) { + $mailer->isSendmail(); + } else { + $mailer->isSMTP(); + } $available_options = [ 'host' => 'Host', diff --git a/create_classic_poll.php b/create_classic_poll.php index e72a8af..bdff627 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -31,7 +31,7 @@ include_once __DIR__ . '/app/inc/init.php'; /*---------*/ $logService = new LogService(); $pollService = new PollService($connect, $logService); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $purgeService = new PurgeService($connect, $logService); $sessionService = new SessionService(); diff --git a/create_date_poll.php b/create_date_poll.php index 42fef6c..2aee276 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -31,7 +31,7 @@ include_once __DIR__ . '/app/inc/init.php'; /*---------*/ $logService = new LogService(); $pollService = new PollService($connect, $logService); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $purgeService = new PurgeService($connect, $logService); $inputService = new InputService(); $sessionService = new SessionService(); diff --git a/find_polls.php b/find_polls.php index d276187..00d9150 100644 --- a/find_polls.php +++ b/find_polls.php @@ -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'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); /* PAGE */ /* ---- */ diff --git a/studs.php b/studs.php index 72d0ce4..27b8fe3 100644 --- a/studs.php +++ b/studs.php @@ -58,7 +58,7 @@ $selectedNewVotes = []; $logService = new LogService(); $pollService = new PollService($connect, $logService); $inputService = new InputService(); -$mailService = new MailService($config['use_smtp'], $config['smtp_options']); +$mailService = new MailService($config['use_smtp'], $config['smtp_options'], $config['use_sendmail']); $notificationService = new NotificationService($mailService); $securityService = new SecurityService(); $sessionService = new SessionService(); diff --git a/tpl/admin/config.tpl b/tpl/admin/config.tpl index aade507..8e2f577 100644 --- a/tpl/admin/config.tpl +++ b/tpl/admin/config.tpl @@ -101,7 +101,8 @@ const DEMO_POLL_NUMBER_VOTES = 10; // Config $config = [ /* general config */ - 'use_smtp' => true, // use email for polls creation/modification/responses notification + 'use_smtp' => true, // use email for polls creation/modification/responses notification (uses smtp only if `use_sendmail` is disabled) + 'use_sendmail' => false, // use sendmail instead of smtp 'smtp_options' => [ 'host' => 'localhost', // SMTP server (you could add many servers (main and backup for example) : use ";" like separator 'auth' => false, // Enable SMTP authentication