This repository has been archived by the owner on May 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcuts.php
52 lines (46 loc) · 1.66 KB
/
shortcuts.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
<?php
/**
* (c) Joffrey Demetz <joffrey.demetz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use JDZ\Mailer\MailerHelper;
/**
* Send a mail
*
* @param array $data Mail data
* - recepient array|string Recipient (either an array [0]=>email [1]=>name or just an email)
* - subject string Subject
* - body string Message body
* - attachment array|string Attachment files (either an array [0]=>attachments [1]=>names or just an attachment)
* - cc array|string CC (either an array [0]=>emails [1]=>names or just an email)
* - bcc array|string BCC (either an array [0]=>emails [1]=>names or just an email)
* - replyTo array|string Reply to (either an array [0]=>emails [1]=>names or just an email)
* @param array $config Mailer config
* @param bool $exceptionOnError Throw a runtime exception on error
* @return bool True if mail was sent
* @throw RuntimeException
*/
function MailIt(array $data, array $config=[], $exceptionOnError=true)
{
$data = array_merge([
'recepient' => null,
'subject' => null,
'body' => null,
'replyTo' => null,
'attachment' => null,
'cc' => null,
'bcc' => null,
], $data);
$result = false;
try {
$result = MailerHelper::sendMail($config, $data);
}
catch(MailerException $e){
if ( $exceptionOnError === true ){
throw new RuntimeException($e->getMessage());
}
}
return $result;
}