2){ $client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4); } $mail = new PHPMailer(true); try{ //Mail Server Settings //$mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $config_smtp_host; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $config_smtp_username; // SMTP username $mail->Password = $config_smtp_password; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = $config_smtp_port; // TCP port to connect to //Recipients $mail->setFrom($config_mail_from_email, $config_mail_from_name); $mail->addAddress("$client_email", "$client_name"); // Add a recipient // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = "Invoice $invoice_number"; $mail->Body = "Hello $client_name,

Please view the details of the invoice below.

Invoice: $invoice_number
Issue Date: $invoice_date
Total: $$invoice_amount
Due Date: $invoice_due


To view your invoice online click here


~
$company_name
$config_company_phone"; $mail->send(); mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id"); //Update Invoice Status to Sent mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), client_id = $client_id WHERE invoice_id = $new_invoice_id"); }catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_created_at = NOW(), invoice_id = $new_invoice_id, company_id = $company_id"); } //End Mail Try } //End if Autosend is on } //End Recurring Invoices Loop //Send Alert to inform Cron was run mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Cron', alert_message = 'Cron.php successfully executed', alert_date = NOW(), company_id = $company_id"); } //End Cron Check } //End Company Loop through ?>