trim(mb_substr((string) ($_POST['note'] ?? ''), 0, 2000))]); $attach_pdf = array_key_exists('attach_pdf', $_POST) ? !empty($_POST['attach_pdf']) : billingReminderRules()['attach_pdf']; $attach = []; if ($attach_pdf && ($file = billingEmailPdf(billingPdf('quote', $quote)))) { $attach[] = $file; } $sent = billingEmailQueue($recipients, $subject, $email, ['from' => 'quote', 'attach' => $attach]); $by = 'the API (' . html_entity_decode($api_key_name, ENT_QUOTES, 'UTF-8') . ')'; billingLog('quote', $quote_id, $quote['quote_status'] === 'Draft' ? 'Sent' : $quote['quote_status'], "Quote emailed by $by to " . implode(', ', $sent) . ($attach ? ' with the PDF' : '')); // Sending a draft sends it - anything further along keeps its status if ($quote['quote_status'] === 'Draft') { mysqli_query($mysqli, "UPDATE quotes SET quote_status = 'Sent' WHERE quote_id = $quote_id"); } $update_count = 1; $return_arr['emailed_to'] = $sent; $return_arr['status'] = (string) getFieldById('quotes', $quote_id, 'quote_status'); $return_arr['url'] = billingGuestUrl('quote', $quote); $reference = escapeSql($reference); foreach ($recipients as $recipient) { logAudit("Quote", "Email", "Emailed quote $reference to " . escapeSql($recipient['email']) . " via API ($api_key_name)", $client_id, $quote_id); } logAudit("API", "Success", "Sent quote $reference via API ($api_key_name)", $client_id); } // Output require_once '../update_output.php';