-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserMail.php
64 lines (51 loc) · 1.47 KB
/
UserMail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace app\Helpers;
class UserMail
{
public static function send($subject, $email, $data, $view,$extra = array())
{
\Mail::send($view, $data, function($message) use ($data, $email, $subject,$extra)
{
self::buildMail($message,$extra,$email, $subject);
});
}
public static function sendToMany($subject, $emails = array(), $data, $view)
{
foreach ($emails as $email) {
\Mail::send($view, $data, function($message) use ($data, $email, $subject,$extra)
{
self::buildMail($message,$extra,$email, $subject);
});
}
}
public static function sendToGroup($subject, $emails = array(), $data, $view)
{
\Mail::send($view, $data, function($message) use ($data, $email, $subject)
{
\Mail::send($view, $data, function($message) use ($data, $email, $subject,$extra)
{
self::buildMail($message,$extra,$email, $subject);
});
});
}
private static function buildMail($message, $extra, $email, $subject)
{
$message->subject($subject);
$message->from(env('MAIL_FROM'), env('MAIL_NAME'));
$message->to($email);
if (isset($extra['cc'])) {
$message->cc($extra['cc'], $name = null);
}
if (isset($extra['bcc'])) {
$message->bcc($extra['bcc'], $name = null);
}
if (isset($extra['replyTo'])) {
$message->replyTo($extra['replyTo'], $name = null);
}
if (isset($extra['attach'])) {
$message->attach($extra['attach']);
}
return $message;
}
}
?>