|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Core\Services\Mail; |
|
4
|
|
|
|
|
5
|
|
|
use Core\Config; |
|
6
|
|
|
use PHPMailer\PHPMailer\SMTP; |
|
7
|
|
|
use Core\Services\Gloabls\Globals; |
|
|
|
|
|
|
8
|
|
|
use PHPMailer\PHPMailer\Exception; |
|
9
|
|
|
use PHPMailer\PHPMailer\PHPMailer; |
|
10
|
|
|
|
|
11
|
|
|
class Mail |
|
12
|
|
|
{ |
|
13
|
|
|
private $mail; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->initMail(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Initiate a Mail object |
|
22
|
|
|
* @return void |
|
23
|
|
|
* @throws Exception |
|
24
|
|
|
*/ |
|
25
|
|
|
private function initMail() |
|
26
|
|
|
{ |
|
27
|
|
|
$config = Config::getInstance(ROOT . '/config/config.php'); |
|
28
|
|
|
$this->mail = new PHPMailer; |
|
29
|
|
|
if (!empty($config->get('smtp_debug'))) { |
|
30
|
|
|
$this->mail->isSMTP(); |
|
31
|
|
|
$this->mail->SMTPDebug = intval($config->get('smtp_debug')); |
|
32
|
|
|
$this->mail->Host = $config->get('smtp_host'); |
|
33
|
|
|
$this->mail->Port = intval($config->get('smtp_port')); |
|
34
|
|
|
if ($config->get('smtp_auth') == 1) { |
|
35
|
|
|
$this->mail->SMTPAuth = !empty($config->get('smtp_auth')); |
|
36
|
|
|
$this->mail->Username = $config->get('smtp_user'); |
|
37
|
|
|
$this->mail->Password = $config->get('smtp_pass'); |
|
38
|
|
|
} |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->mail->isMail(); |
|
41
|
|
|
} |
|
42
|
|
|
$this->mail->CharSet = 'UTF-8'; |
|
43
|
|
|
$this->mail->setLanguage('fr'); |
|
44
|
|
|
$this->mail->WordWrap = 78; |
|
45
|
|
|
$this->mail->addAddress($config->get('mail_address')); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Generate the Mail sending |
|
50
|
|
|
* @param array $POST |
|
51
|
|
|
* @return array with the \compat function | !! use \extract to retrieve |
|
52
|
|
|
*/ |
|
53
|
|
|
public function sendMail(array $POST): array |
|
54
|
|
|
{ |
|
55
|
|
|
$errors = ''; |
|
56
|
|
|
$message = ''; |
|
57
|
|
|
|
|
58
|
|
|
$this->mail->setFrom($POST['mail'], $POST['name']); |
|
59
|
|
|
$this->mail->Subject = $POST['subject']; |
|
60
|
|
|
$this->mail->Body = nl2br($POST['content']); |
|
61
|
|
|
$this->mail->AltBody = nl2br($POST['content']); |
|
62
|
|
|
$this->mail->IsHTML(false); |
|
63
|
|
|
|
|
64
|
|
|
if (!$this->mail->send()) { |
|
65
|
|
|
$errors = $this->mail->ErrorInfo; |
|
66
|
|
|
} else { |
|
67
|
|
|
$message = 'Message envoyé !'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return \compact('errors', 'message'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths