$kind, 'note' => $note]); $attach = []; if ($attach_pdf && ($file = billingEmailPdf(billingPdf('invoice', $invoice)))) { $attach[] = $file; } $sent = billingEmailQueue($recipients, $subject, $email, ['attach' => $attach]); $reminder = $kind === 'reminder' && $email['kind'] === 'Payment reminder'; // Texted with its link too, to those of them who agreed to texts (functions/sms.php) $texted = smsInvoiceNotify($invoice, $reminder ? 'reminder' : 'invoice', $recipients); $by = 'the API (' . html_entity_decode($api_key_name, ENT_QUOTES, 'UTF-8') . ')'; billingLog('invoice', $invoice_id, $invoice['invoice_status'] === 'Draft' ? 'Sent' : $invoice['invoice_status'], ($reminder ? 'Reminder emailed' : 'Invoice emailed') . " by $by to " . implode(', ', $sent) . ($attach ? ' with the PDF' : '') . ($texted ? ' - and texted to ' . implode(', ', $texted) : '')); // Sending a draft sends it - anything further along keeps its status if ($invoice['invoice_status'] === 'Draft') { mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Sent' WHERE invoice_id = $invoice_id"); } $update_count = 1; $return_arr['emailed_to'] = $sent; $return_arr['status'] = (string) getFieldById('invoices', $invoice_id, 'invoice_status'); $return_arr['url'] = billingGuestUrl('invoice', $invoice); $reference = escapeSql($reference); foreach ($recipients as $recipient) { logAudit("Invoice", "Email", "Emailed " . escapeSql($recipient['email']) . ($reminder ? " a reminder for" : "") . " invoice $reference via API ($api_key_name)", $client_id, $invoice_id); } logAudit("API", "Success", ($reminder ? "Sent a reminder for" : "Sent") . " invoice $reference via API ($api_key_name)", $client_id); } // Output require_once '../update_output.php';