diff --git a/action/add_comment.php b/action/add_comment.php index df75385190afa2b52a3d25f007d0ab7b601b30f7..d4247eb5c6a1403603fe1b20c1021bd96a7bde5d 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 a2ac204de5958bd9895a4d9a78e2e7f3d80b26da..1097e7a8d78b8486f86311d9660d0b27327eeea2 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 f4e472e2da2c987e4a51956abe635deef3fd8edf..407e23d8bb41311065535c5492c2a72f1301bc15 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 9c32f3f6fe52e6d4efe843c3a60a3d589672055b..fdc58d97c360d43840c6d01f1a1e5630313257e9 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 e72a8af7c01ee22af34ffe6e2f3f882e91c88b92..bdff627e65d143ce5d6eaff5d3197349547bb7e2 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 42fef6cf271ab8fafbb9a0a12a0ccf674c555155..2aee276d31f7c889ad5783c82d16f9c27b9a7c4a 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 d27618776d8899e26cc9a0192a326bb52a44993c..00d91505662e4db0808c6943779e0f1572df6697 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 72d0ce4fd7e0e4088ebe99eaa257db275947e2a1..27b8fe3e74895c954599dec0f93a85332a363121 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 aade5072aa11b949fbd264cc9d5e1e299963d13a..8e2f5774a07e53e0009bfaa8f41cb6cc01a78892 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