Deploy Ladill Queue / deploy (push) Successful in 43s
Customer-facing outbound mail should appear from the business (organizer, clinic, company, location), not the Ladill product brand.
44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Comms;
|
|
|
|
use App\Mail\ContactMessageMail;
|
|
use App\Models\Organization;
|
|
use App\Support\OrganizationBranding;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
/**
|
|
* Outbound email to contacts. Uses the app's configured mailer (set MAIL_* to
|
|
* a Ladill Bird SMTP credential in production so mail leaves as the account's
|
|
* sender). Failures are swallowed + logged; the caller decides what to record.
|
|
*/
|
|
class EmailService
|
|
{
|
|
public function send(string $to, string $subject, string $body, ?string $fromName = null, ?string $replyTo = null, ?Organization $organization = null): bool
|
|
{
|
|
if (! filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
|
return false;
|
|
}
|
|
|
|
$logoUrl = null;
|
|
$companyName = null;
|
|
if ($organization) {
|
|
$logoUrl = OrganizationBranding::emailLogoUrl($organization);
|
|
$companyName = $organization->name;
|
|
}
|
|
// Client-facing From display: org/company name, never the Ladill product brand.
|
|
$displayName = trim((string) ($fromName ?: $companyName)) ?: null;
|
|
|
|
try {
|
|
Mail::to($to)->send(new ContactMessageMail($subject, $body, $displayName, $replyTo, $logoUrl, $companyName));
|
|
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Log::warning('CRM email send failed', ['to' => $to, 'error' => $e->getMessage()]);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|