2015-03-24 09:21:12 +01:00
|
|
|
<?php namespace App\Ninja\Mailers;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
use Mail;
|
|
|
|
use Utils;
|
2015-04-06 08:58:47 +02:00
|
|
|
use App\Models\Invoice;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
class Mailer
|
|
|
|
{
|
|
|
|
public function sendTo($toEmail, $fromEmail, $fromName, $subject, $view, $data = [])
|
|
|
|
{
|
|
|
|
$views = [
|
|
|
|
'emails.'.$view.'_html',
|
|
|
|
'emails.'.$view.'_text',
|
|
|
|
];
|
|
|
|
|
2015-03-15 13:01:13 +01:00
|
|
|
Mail::send($views, $data, function ($message) use ($toEmail, $fromEmail, $fromName, $subject, $data) {
|
2015-03-16 22:45:25 +01:00
|
|
|
$replyEmail = $fromEmail;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-04-22 23:40:21 +02:00
|
|
|
if(isset($data['invoice_id'])) {
|
|
|
|
$invoice = Invoice::scope($data['invoice_id'])->with(['account'])->first();
|
2015-03-24 17:07:48 +01:00
|
|
|
$pdfPath = storage_path().'/pdfcache/cache-'.$invoice->id.'.pdf';
|
2015-04-22 23:40:21 +02:00
|
|
|
if($invoice->account->pdf_email_attachment && file_exists($pdfPath)) {
|
2015-03-15 13:01:13 +01:00
|
|
|
$message->attach(
|
|
|
|
$pdfPath,
|
2015-04-22 23:40:21 +02:00
|
|
|
array('as' => $invoice->getFileName(), 'mime' => 'application/pdf')
|
2015-03-15 13:01:13 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
//$message->setEncoder(\Swift_Encoding::get8BitEncoding());
|
|
|
|
$message->to($toEmail)->from($fromEmail, $fromName)->replyTo($replyEmail, $fromName)->subject($subject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|