diff --git a/app/Http/Controllers/SmtpController.php b/app/Http/Controllers/SmtpController.php index edfc24c38689..629a92bc1b48 100644 --- a/app/Http/Controllers/SmtpController.php +++ b/app/Http/Controllers/SmtpController.php @@ -55,7 +55,17 @@ class SmtpController extends BaseController (new \Illuminate\Mail\MailServiceProvider(app()))->register(); try { - Mail::mailer('smtp')->to($user->email, $user->present()->name())->send(new TestMailServer('Email Server Works!', strlen($company->settings->custom_sending_email) > 1 ? $company->settings->custom_sending_email : $user->email)); + + $sending_email = (isset($company->settings->custom_sending_email) && stripos($company->settings->custom_sending_email, "@")) ? $company->settings->custom_sending_email : $user->email; + $sending_user = (isset($company->settings->email_from_name) && strlen($company->settings->email_from_name) > 2) ? $company->settings->email_from_name : $user->name(); + + $mailable = new TestMailServer('Email Server Works!', $sending_email); + $mailable->from($sending_email,$sending_user); + + Mail::mailer('smtp') + ->to($user->email, $user->present()->name()) + ->send($mailable); + } catch (\Exception $e) { app('mail.manager')->forgetMailers(); return response()->json(['message' => $e->getMessage()], 400); diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index def24172b528..5bed2111b564 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -76,12 +76,12 @@ class SendRecurring implements ShouldQueue $invoice = $invoice->service() ->markSent() ->applyNumber() - ->fillDefaults() + ->fillDefaults(true) ->adjustInventory() ->save(); } else { $invoice = $invoice->service() - ->fillDefaults() + ->fillDefaults(true) ->save(); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index effe34daceba..dbe57e361b3c 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -544,7 +544,7 @@ class InvoiceService return $this; } - public function fillDefaults() + public function fillDefaults(bool $is_recurring = false) { $this->invoice->load('client.company'); @@ -571,7 +571,7 @@ class InvoiceService $this->invoice->exchange_rate = $this->invoice->client->setExchangeRate(); } - if ($this->invoice->client->getSetting('auto_bill_standard_invoices')) { + if ($is_recurring && $this->invoice->client->getSetting('auto_bill_standard_invoices')) { $this->invoice->auto_bill_enabled = true; }