add projet

This commit is contained in:
root
2026-03-05 12:29:37 -05:00
parent 8d1eef8ba8
commit 23b7db1107
9109 changed files with 1106501 additions and 73 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class EmailService
{
protected array $from = [];
protected array $to = [];
protected string $subject = '';
protected string $message = '';
public function setFrom(string $email, string $name = ''): self
{
$this->from = ['email' => $email, 'name' => $name];
return $this;
}
public function setTo(string|array $email): self
{
$this->to = is_array($email) ? $email : [$email];
return $this;
}
public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function send(string $to = '', string $subject = '', string $message = '', ?string $template = null): bool
{
if (!empty($to)) {
$this->setTo($to);
}
if ($subject !== '') {
$this->setSubject($subject);
}
if ($message !== '') {
$this->setMessage($message);
}
if (empty($this->to)) {
return false;
}
try {
Mail::html($this->message, function ($mail) use ($template) {
$mail->to($this->to);
if (!empty($this->from)) {
$mail->from($this->from['email'], $this->from['name']);
}
$mail->subject($this->subject);
});
return true;
} catch (\Throwable $e) {
Log::error('EmailService send failed: ' . $e->getMessage());
return false;
}
}
}