forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLumenMailer.php
65 lines (55 loc) · 1.74 KB
/
LumenMailer.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
65
<?php
/**
* Ushahidi Mailer
*
* @author Ushahidi Team <[email protected]>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
namespace Ushahidi\App\Tools;
use Ushahidi\Core\Tool\Mailer as MailerContract;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Support\Str;
use Ushahidi\App\Multisite\UsesSiteInfo;
class LumenMailer implements MailerContract
{
use UsesSiteInfo;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function send($to, $type, array $params = null)
{
// Only available type right now is 'resetpassword'
$method = "send" . Str::ucfirst($type);
if (method_exists($this, $method)) {
$this->$method($to, $params);
} else {
// Exception
throw new Exception('Unsupported mail type: ' + $type);
}
}
protected function sendResetpassword($to, $params)
{
$site_name = $this->getSite()->getName();
$site_email = $this->getSite()->getEmail();
$data = [
'site_name' => $site_name,
'token' => $params['token'],
'client_url' => $this->getSite()->getClientUri()
];
$subject = $site_name . ': Password reset';
$this->mailer->send(
'emails/forgot-password',
$data,
function ($message) use ($to, $subject, $site_email, $site_name) {
$message->to($to);
$message->subject($subject);
if ($site_email) {
$message->from($site_email, $site_name);
}
}
);
}
}