2013-12-25 22:34:42 +01:00
|
|
|
<?php namespace ninja\mailers;
|
2013-12-10 18:18:35 +01:00
|
|
|
|
|
|
|
use Mail;
|
2014-09-12 14:11:59 +02:00
|
|
|
use Utils;
|
2015-03-15 13:01:13 +01:00
|
|
|
use Invoice;
|
2013-12-10 18:18:35 +01:00
|
|
|
|
2015-01-11 13:30:08 +01:00
|
|
|
class Mailer
|
|
|
|
{
|
|
|
|
public function sendTo($toEmail, $fromEmail, $fromName, $subject, $view, $data = [])
|
|
|
|
{
|
|
|
|
$views = [
|
|
|
|
'emails.'.$view.'_html',
|
|
|
|
'emails.'.$view.'_text',
|
|
|
|
];
|
2013-12-10 18:18:35 +01:00
|
|
|
|
2015-03-15 13:01:13 +01:00
|
|
|
Mail::send($views, $data, function ($message) use ($toEmail, $fromEmail, $fromName, $subject, $data) {
|
2015-01-11 13:30:08 +01:00
|
|
|
$replyEmail = $fromEmail;
|
2014-11-19 20:51:53 +01:00
|
|
|
|
2015-01-11 13:30:08 +01:00
|
|
|
// http://stackoverflow.com/questions/2421234/gmail-appearing-to-ignore-reply-to
|
|
|
|
if (Utils::isNinja() && $toEmail != CONTACT_EMAIL) {
|
|
|
|
$fromEmail = NINJA_FROM_EMAIL;
|
|
|
|
}
|
2015-03-15 13:01:13 +01:00
|
|
|
|
|
|
|
if(isset($data['id'])) {
|
|
|
|
$invoice = Invoice::find($data['id']);
|
|
|
|
$invoice->load('account');
|
|
|
|
$accountAttributes = $invoice->account()->getParent()->getRelations()['account']->getAttributes();
|
|
|
|
$pdfPath = storage_path().'/pdfcache/cache-'.$invoice->getAttributes()['public_id'].'.pdf';
|
|
|
|
|
|
|
|
if($accountAttributes['pdf_email_attachment'] === 1 && file_exists($pdfPath)) {
|
|
|
|
$message->attach(
|
|
|
|
$pdfPath,
|
|
|
|
array('as' => $accountAttributes['name'].'_'.$accountAttributes['invoice_number_prefix'].$invoice->getName().'.pdf', 'mime' => 'application/pdf')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 14:11:59 +02:00
|
|
|
|
2015-03-10 13:39:25 +01:00
|
|
|
//$message->setEncoder(\Swift_Encoding::get8BitEncoding());
|
2015-01-11 13:30:08 +01:00
|
|
|
$message->to($toEmail)->from($fromEmail, $fromName)->replyTo($replyEmail, $fromName)->subject($subject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|