init smtp server

This commit is contained in:
Fred Tempez 2020-05-10 18:06:57 +02:00
parent 46a5a6b128
commit 5542ba5193
6 changed files with 1491 additions and 20 deletions

View File

@ -7,6 +7,7 @@ class autoload {
require_once 'core/class/SitemapGenerator.class.php'; require_once 'core/class/SitemapGenerator.class.php';
require_once 'core/class/phpmailer/PHPMailer.class.php'; require_once 'core/class/phpmailer/PHPMailer.class.php';
require_once 'core/class/phpmailer/Exception.class.php'; require_once 'core/class/phpmailer/Exception.class.php';
require_once 'core/class/phpmailer/SMTP.class.php';
require_once "core/class/jsondb/Dot.class.php"; require_once "core/class/jsondb/Dot.class.php";
require_once "core/class/jsondb/JsonDb.class.php"; require_once "core/class/jsondb/JsonDb.class.php";
} }

File diff suppressed because it is too large Load Diff

View File

@ -846,18 +846,30 @@ class common {
* @return bool * @return bool
*/ */
public function sendMail($to, $subject, $content, $replyTo = null) { public function sendMail($to, $subject, $content, $replyTo = null) {
// Utilisation de PHPMailer version 6.0.6
//require_once "core/vendor/phpmailer/phpmailer.php";
//require_once "core/vendor/phpmailer/exception.php";
// Layout // Layout
ob_start(); ob_start();
include 'core/layout/mail.php'; include 'core/layout/mail.php';
$layout = ob_get_clean(); $layout = ob_get_clean();
$mail = new PHPMailer\PHPMailer\PHPMailer;
// $mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
// Mail // Mail
try{ try{
$mail = new PHPMailer\PHPMailer\PHPMailer; // Paramètres SMTP
$mail->CharSet = 'UTF-8'; if ($this->getdata(['config','smtp','enable'])) {
$mail->isSMTP();
$mail->Host = $this->getdata(['config','smtp','host']);
$mail->Port = (int) $this->getdata(['config','smtp','port']);
if ($this->getData(['config','smtp','auth'])) {
$mail->Username = $this->getData(['config','smtp','username']);
$mail->Password = $this->getData(['config','smtp','password']);
$mail->SMTPAuth = $this->getData(['config','smtp','auth']);
$mail->SMTPSecure = $this->getData(['config','smtp','secure']);
$mail->setFrom($this->getData(['config','smtp','sender']));
}
// Fin SMTP
} else {
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']); $host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title'])); $mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title']));
if (is_null($replyTo)) { if (is_null($replyTo)) {
@ -865,6 +877,8 @@ class common {
} else { } else {
$mail->addReplyTo($replyTo); $mail->addReplyTo($replyTo);
} }
}
$mail->CharSet = 'UTF-8';
if(is_array($to)) { if(is_array($to)) {
foreach($to as $userMail) { foreach($to as $userMail) {
$mail->addAddress($userMail); $mail->addAddress($userMail);
@ -904,8 +918,6 @@ class common {
//Retourne une chaine contenant le dossier à créer //Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr'); $folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB // Constructeur JsonDB
//require_once "core/vendor/jsondb/Dot.php";
//require_once "core/vendor/jsondb/JsonDb.php";
$db = new \Prowebcraft\JsonDb([ $db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json', 'name' => $keys[0] . '.json',
'dir' => $folder, 'dir' => $folder,
@ -1426,6 +1438,7 @@ class core extends common {
* @param string $className Nom de la classe à charger * @param string $className Nom de la classe à charger
*/ */
public static function autoload($className) { public static function autoload($className) {
$classPath = strtolower($className) . '/' . strtolower($className) . '.php'; $classPath = strtolower($className) . '/' . strtolower($className) . '.php';
// Module du coeur // Module du coeur
if(is_readable('core/module/' . $classPath)) { if(is_readable('core/module/' . $classPath)) {

View File

@ -153,6 +153,17 @@ class config extends common {
'tcp://' => 'TCP', 'tcp://' => 'TCP',
'http://' => 'HTTP' 'http://' => 'HTTP'
]; ];
// Authentification SMTP
public static $SMTPauth = [
true => 'Oui',
false => 'Non'
];
// Encryptation SMTP
public static $SMTPEnc = [
'' => 'Aucune',
'tls' => 'START TLS',
'ssl' => 'SSL/TLS'
];
public function generateFiles() { public function generateFiles() {
@ -419,7 +430,17 @@ class config extends common {
: $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN), : $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN),
'proxyType' => $this->getInput('configProxyType'), 'proxyType' => $this->getInput('configProxyType'),
'proxyUrl' => $this->getInput('configProxyUrl'), 'proxyUrl' => $this->getInput('configProxyUrl'),
'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT) 'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT),
'smtp' => [
'enable' => $this->getInput('configSmtpEnable',helper::FILTER_BOOLEAN),
'host' => $this->getInput('configSmtpHost',helper::FILTER_STRING_SHORT),
'port' => $this->getInput('configSmtpPort',helper::FILTER_INT),
'auth' => $this->getInput('configSmtpAuth',helper::FILTER_BOOLEAN),
'secure' => $this->getInput('configSmtpSecure'),
'username' => $this->getInput('configSmtpUsername',helper::FILTER_STRING_SHORT),
'password' => $this->getInput('configSmtpPassword'),
'sender' => $this->getInput('configSmtpSender',helper::FILTER_MAIL)
]
] ]
]); ]);

View File

@ -323,6 +323,70 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Paramètres de messagerie SMTP</h4>
<div class="row">
<div class="col12">
<?php echo template::checkbox('configSmtpEnable', true, 'Activer STMP', [
'checked' => $this->getData(['config', 'smtp','enable']),
'help' => 'Paramètres à utiliser lorsque votre hébergeur ne propose pas la fonctionnalité d\'envoi de mail.'
]); ?>
</div>
</div>
<div class="row">
<div class="col5">
<?php echo template::text('configSmtpHost', [
'label' => 'Adresse SMTP',
'placeholder' => 'smtp.fr',
'value' => $this->getData(['config', 'smtp','host'])
]); ?>
</div>
<div class="col5">
<?php echo template::text('configSmtpSender', [
'label' => 'Mail expéditeur',
'value' => $this->getData(['config', 'smtp','sender'])
]); ?>
</div>
<div class="col2">
<?php echo template::text('configSmtpPort', [
'label' => 'Port SMTP',
'placeholder' => '589',
'value' => $this->getData(['config', 'smtp','port'])
]); ?>
</div>
</div>
<div class="row">
<div class="col2">
<?php echo template::select('configSmtpAuth', $module::$SMTPauth, [
'label' => 'Authentification',
'selected' => $this->getData(['config', 'smtp','auth'])
]); ?>
</div>
<div class="col4">
<?php echo template::text('configSmtpUsername', [
'label' => 'Nom utilisateur',
'value' => $this->getData(['config', 'smtp','username' ])
]); ?>
</div>
<div class="col4">
<?php echo template::password('configSmtpPassword', [
'label' => 'Mot de passe',
'autocomplete' => 'off',
'value' => $this->getData(['config', 'smtp','password' ])
]); ?>
</div>
<div class="col2">
<?php echo template::select('configSmtpSecure', $module::$SMTPEnc , [
'label' => 'Sécurité',
'selected' => $this->getData(['config', 'smtp','secure'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col12"> <div class="col12">
<div class="block"> <div class="block">

View File

@ -30,6 +30,7 @@ setlocale (LC_TIME, 'fra_FRA', 'french');
*/ */
session_start(); session_start();
// Chargement des classes // Chargement des classes
require 'core/class/autoload.php'; require 'core/class/autoload.php';
autoload::autoloader(); autoload::autoloader();
// Chargement du coeur // Chargement du coeur