# Phase 19 — Notifications & Email

This phase adds:

- In-app notifications for the logged-in user.
- Notification list with unread count, mark-read and mark-all-read.
- SMTP configuration in Settings → Email delivery.
- **Email Invoice PDF** action on an existing invoice.
- The current branded invoice PDF is attached automatically.
- Patient email is read from the patient record.
- Email sends are recorded as an in-app notification for the staff user who sent them.

## Migration

Run once against `grow_tool_therapies_crm`:

`database/migrations/013_phase19_notifications_email.sql`

Do not rerun previous migrations.

## SMTP setup

Open:

`http://localhost/crm/public/settings`

Under **Email delivery**, enter your SMTP host, port, username/password, encryption and sender email/name.

Examples:

- TLS: port 587
- SSL: port 465

The CRM uses PHPMailer already included in `composer.json`.

## Sending an invoice

Open an invoice and click **Email Invoice PDF**.

The CRM checks the patient's email address, generates the current branded invoice PDF, attaches it and sends it through SMTP.

If the patient has no email, add one under the patient profile first.
