1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 15:42:51 +01:00
invoiceninja/app/ninja/mailers/Mailer.php

43 lines
1.6 KiB
PHP
Raw Normal View History

2013-12-25 22:34:42 +01:00
<?php namespace ninja\mailers;
2013-12-10 18:18:35 +01:00
use Mail;
use Utils;
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
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;
}
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')
);
}
}
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);
});
}
}