Skip to content

Commit c86b77a

Browse files
committed
Make Mailer more customizable
1 parent 312f315 commit c86b77a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ MAILER_PASSWORD=password
4343
MAILER_DISPLAY_EMAIL=info@example.com
4444
MAILER_DISPLAY_FROM="Web Toolkit"
4545
MAILER_MAX_BATCH_SIZE=25
46+
MAILER_AUTH=true
47+
MAILER_ENCRYPT=ssl
4648

4749
#
4850
# Two Factor Setup

src/App/Controller/Administration/AccountViewController.php

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function load(ServerRequestInterface $request, array $args): ResponseInte
5656
$viewAccount->setLevel($viewAccountData['level']);
5757
$viewAccount->setSupport($viewAccountData['isSupport'] === 1);
5858
$viewAccount->setAdmin($viewAccountData['isAdmin'] === 1);
59+
$viewAccount->setDefaultShippingAddress($viewAccountData['defaultShippingAddress']);
60+
$viewAccount->setDefaultInvoiceAddress($viewAccountData['defaultInvoiceAddress']);
5961

6062
if ($request->getMethod() === 'POST') {
6163
$this->manage($request, $viewAccount);

src/App/Factory/MailerFactory.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@ public function __construct(
1717
public function getMailer(): PHPMailer
1818
{
1919
$this->mailer->isSMTP();
20-
$this->mailer->SMTPAuth = true;
20+
$this->mailer->SMTPAuth = $_ENV['MAILER_AUTH'] ?? 'true' == 'true';
2121
$this->mailer->Host = $_ENV['MAILER_HOST'];
2222
$this->mailer->Username = $_ENV['MAILER_USERNAME'];
2323
$this->mailer->Password = $_ENV['MAILER_PASSWORD'];
2424
$this->mailer->Port = $_ENV['MAILER_PORT'];
2525
$this->mailer->setFrom($_ENV['MAILER_DISPLAY_EMAIL'], $_ENV['MAILER_DISPLAY_FROM']);
26-
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
26+
switch ($_ENV['MAILER_ENCRYPTION'] ?? "none") {
27+
case "tls":
28+
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
29+
break;
30+
case "ssl":
31+
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
32+
break;
33+
case "none":
34+
$this->mailer->SMTPSecure = false;
35+
$this->mailer->SMTPAutoTLS = false;
36+
break;
37+
default:
38+
$this->mailer->SMTPSecure = false;
39+
break;
40+
}
2741

2842
$this->mailer->CharSet = 'UTF-8';
2943
$this->mailer->Encoding = 'base64';

0 commit comments

Comments
 (0)