forked from fahmiardi/slim-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.php
More file actions
35 lines (28 loc) · 836 Bytes
/
Copy pathmail.php
File metadata and controls
35 lines (28 loc) · 836 Bytes
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
<?php
class Mail {
function send($msg = '', $data = array()) {
global $app;
$mandrill = new Mandrill(config('mandrill.apikey'));
if (!is_array($msg)) {
parse_str($msg, $msg);
}
foreach(array('text', 'html') as $t) {
if (!empty($msg[$t]) && strpos(trim($msg[$t]), 'slim:') === 0) {
$view = new \Slim\View();
$view->appendData($data);
$view->setTemplatesDirectory($app->config('templates.path'));
$msg[$t] = $view->fetch('email/'.substr(trim($msg[$t]), 5));
}
}
if (isset($msg['from'])) {
$msg['from_email'] = $msg['from'];
unset($msg['from']);
}
if (!is_array($msg['to'])) {
$msg['to'] = array(
array('email' => $msg['to'])
);
}
return $mandrill->call('/messages/send', array('message' => $msg));
}
}