1 | <?php |
||||||
2 | /** |
||||||
3 | * This file is part of the O2System Framework package. |
||||||
4 | * |
||||||
5 | * For the full copyright and license information, please view the LICENSE |
||||||
6 | * file that was distributed with this source code. |
||||||
7 | * |
||||||
8 | * @author Steeve Andrian Salim |
||||||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||||
10 | */ |
||||||
11 | |||||||
12 | // ------------------------------------------------------------------------ |
||||||
13 | |||||||
14 | namespace O2System\Email\Protocols; |
||||||
15 | |||||||
16 | // ------------------------------------------------------------------------ |
||||||
17 | |||||||
18 | use O2System\Email\Address; |
||||||
19 | use O2System\Email\Message; |
||||||
20 | use PHPMailer\PHPMailer\PHPMailer; |
||||||
21 | |||||||
22 | /** |
||||||
23 | * Class SendMailProtocol |
||||||
24 | * |
||||||
25 | * @package O2System\Email\Protocols |
||||||
26 | */ |
||||||
27 | class SendmailProtocol extends Abstracts\AbstractProtocol |
||||||
28 | { |
||||||
29 | /** |
||||||
30 | * MailProtocol::sending |
||||||
31 | * |
||||||
32 | * Protocol message sending process. |
||||||
33 | * |
||||||
34 | * @param Message $message |
||||||
35 | * |
||||||
36 | * @return bool |
||||||
37 | * @throws \PHPMailer\PHPMailer\Exception |
||||||
38 | */ |
||||||
39 | protected function sending(Message $message) |
||||||
40 | { |
||||||
41 | $phpMailer = new PHPMailer(); |
||||||
42 | $phpMailer->isSendmail(); |
||||||
43 | |||||||
44 | // Set from |
||||||
45 | if (false !== ($from = $message->getFrom())) { |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
46 | $phpMailer->setFrom($from->getEmail(), $from->getName()); |
||||||
0 ignored issues
–
show
It seems like
$from->getEmail() can also be of type false ; however, parameter $address of PHPMailer\PHPMailer\PHPMailer::setFrom() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$from->getName() can also be of type false ; however, parameter $name of PHPMailer\PHPMailer\PHPMailer::setFrom() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
47 | } |
||||||
48 | |||||||
49 | // Set recipient |
||||||
50 | if (false !== ($to = $message->getTo())) { |
||||||
51 | foreach ($to as $address) { |
||||||
52 | if ($address instanceof Address) { |
||||||
53 | $phpMailer->addAddress($address->getEmail(), $address->getName()); |
||||||
0 ignored issues
–
show
It seems like
$address->getEmail() can also be of type false ; however, parameter $address of PHPMailer\PHPMailer\PHPMailer::addAddress() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$address->getName() can also be of type false ; however, parameter $name of PHPMailer\PHPMailer\PHPMailer::addAddress() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
54 | } |
||||||
55 | } |
||||||
56 | } |
||||||
57 | |||||||
58 | // Set reply-to |
||||||
59 | if (false !== ($replyTo = $message->getReplyTo())) { |
||||||
0 ignored issues
–
show
|
|||||||
60 | $phpMailer->addReplyTo($replyTo->getEmail(), $replyTo->getName()); |
||||||
0 ignored issues
–
show
It seems like
$replyTo->getEmail() can also be of type false ; however, parameter $address of PHPMailer\PHPMailer\PHPMailer::addReplyTo() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$replyTo->getName() can also be of type false ; however, parameter $name of PHPMailer\PHPMailer\PHPMailer::addReplyTo() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
61 | } |
||||||
62 | |||||||
63 | // Set content-type |
||||||
64 | if ($message->getContentType() === 'html') { |
||||||
65 | $phpMailer->isHTML(true); |
||||||
66 | } |
||||||
67 | |||||||
68 | // Set subject, body & alt-body |
||||||
69 | $phpMailer->Subject = $message->getSubject(); |
||||||
70 | $phpMailer->Body = $message->getBody(); |
||||||
71 | $phpMailer->AltBody = $message->getAltBody(); |
||||||
72 | |||||||
73 | if (false !== ($attachments = $message->getAttachments())) { |
||||||
74 | foreach ($attachments as $filename => $attachment) { |
||||||
75 | $phpMailer->addAttachment($attachment, $filename); |
||||||
76 | } |
||||||
77 | } |
||||||
78 | |||||||
79 | if ( ! $phpMailer->send()) { |
||||||
80 | $this->addErrors([ |
||||||
81 | $phpMailer->ErrorInfo, |
||||||
82 | ]); |
||||||
83 | |||||||
84 | return false; |
||||||
85 | } |
||||||
86 | |||||||
87 | return true; |
||||||
88 | } |
||||||
89 | } |