You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB
PHP

<?php
namespace App\Services;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
class EmailService
{
public function sendUserFromKey($id, $title, $message, $files = array())
{
$user = User::find($id);
$this->sendUsers( array( $user ), $title, $message, $files);
}
public function sendUser($user, $title, $message, $files = array())
{
$this->sendUsers( array( $user ), $title, $message, $files);
}
public function sendUsers(array $users, $title, $message, $files = array())
{
foreach($users as $user) {
$this->sendEmail($user->userid, $user->name, $title, $message, $files);
}
}
public function sendEmail($email, $name, $title, $messageText, $files = array())
{
Mail::raw( $messageText, function ($message) use ($email, $name, $title, $messageText, $files) {
$message->subject($title);
$message->setBody($messageText, 'text/html');
$message->from('mailer-daemon@dowajwo.com', '도와줘');
$message->to($email, $name);
foreach($files as $file) {
$message->attach($file['path'], ['as' => $file['name']]);
}
});
}
}
?>