Enable sending emails from alternate domain

This commit is contained in:
Hillel Coren 2017-01-12 21:19:13 +02:00
parent 9013321a1b
commit 7a20dc5c12
5 changed files with 43 additions and 5 deletions

View File

@ -21,4 +21,9 @@ class Domain
{
return 'https://app.' . static::getDomainFromId($id);
}
public static function getEmailFromId($id)
{
return 'maildelivery@' . static::getDomainFromId($id);
}
}

View File

@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait;
use App\Models\Traits\PresentsInvoice;
use App\Models\Traits\GeneratesNumbers;
use App\Models\Traits\SendsEmails;
/**
* Class Account
@ -24,6 +25,7 @@ class Account extends Eloquent
use SoftDeletes;
use PresentsInvoice;
use GeneratesNumbers;
use SendsEmails;
/**
* @var string

View File

@ -0,0 +1,24 @@
<?php namespace App\Models\Traits;
use Utils;
use App\Constants\Domain;
/**
* Class SendsEmails
*/
trait SendsEmails
{
public function getBccEmail()
{
return $this->isPro() ? $this->bcc_email : false;
}
public function getFromEmail()
{
if ( ! $this->isPro() || ! Utils::isNinja()) {
return false;
}
return Domain::getEmailFromId($this->domain_id);
}
}

View File

@ -199,7 +199,8 @@ class ContactMailer extends Mailer
'invoice' => $invoice,
'documents' => $documentStrings,
'notes' => $reminder,
'bcc_email' => $account->isPro() ? $account->bcc_email : false,
'bccEmail' => $account->getBccEmail(),
'fromEmail' => $account->getFromEmail(),
];
if ($account->attachPDF()) {
@ -286,7 +287,8 @@ class ContactMailer extends Mailer
'account' => $account,
'payment' => $payment,
'entityType' => ENTITY_INVOICE,
'bcc_email' => $account->isPro() ? $account->bcc_email : false,
'bccEmail' => $account->getBccEmail(),
'fromEmail' => $account->getFromEmail(),
];
if ($account->attachPDF()) {

View File

@ -42,14 +42,19 @@ class Mailer
$replyEmail = $fromEmail;
$fromEmail = CONTACT_EMAIL;
// Optionally send for alternate domain
if (!empty($data['fromEmail'])) {
$fromEmail = $data['fromEmail'];
}
$message->to($toEmail)
->from($fromEmail, $fromName)
->replyTo($replyEmail, $fromName)
->subject($subject);
// Optionally BCC the email
if (!empty($data['bcc_email'])) {
$message->bcc($data['bcc_email']);
if (!empty($data['bccEmail'])) {
$message->bcc($data['bccEmail']);
}
// Attach the PDF to the email
@ -58,7 +63,7 @@ class Mailer
}
// Attach documents to the email
if(!empty($data['documents'])){
if (!empty($data['documents'])){
foreach($data['documents'] as $document){
$message->attachData($document['data'], $document['name']);
}