# BluePeak Self-Hosted PHP Mailer — Setup

Runs on your existing cPanel/MariaDB/PHPMailer stack (same as Kitchen234).
Sends the branded flow emails from recruiting@bluepeakrecruitments.com, and can
host the offer/verification pages on the same domain later.

## 1. Upload
- Upload the whole `bluepeak-php` folder into your cPanel, e.g. to
  `public_html/mail/` (so URLs are `https://bluepeakrecruitments.com/mail/...`).
- Upload the two logo PNGs to `public_html/assets/` so the branding URLs resolve:
  `bluepeak-logo-email.png`, `bluepeak-logo-white.png`.

## 2. Database
- cPanel → **MySQL Databases** → create a database + user, add the user to the DB
  with all privileges.
- cPanel → **phpMyAdmin** → select the DB → **Import** → upload `schema.sql`.

## 3. Configure
- Edit `config.php`:
  - `smtp` — from cPanel → **Email Accounts → Connect Devices** (host is usually
    `mail.bluepeakrecruitments.com`, port 465 SSL, user = the full email address,
    pass = the mailbox password).
  - `db` — the database name/user/pass from step 2.
  - `admin_key` — set a long random string (protects send.php and admin.php).
- The included `.htaccess` blocks web access to `config.php` and `/lib`.

## 4. Send your first email
- Open `https://bluepeakrecruitments.com/mail/admin.php?key=YOUR_ADMIN_KEY`
- **Add an applicant** (yourself, to test).
- **Queue an email** → pick the applicant, choose `application_received`, Queue.
- Click **▶ Send all due emails now** → check your inbox for the branded email.

## 5. Automate sending (cron)
cPanel → **Cron Jobs** → add (every 5 minutes):
```
*/5 * * * * /usr/local/bin/php /home/YOURUSER/public_html/mail/send.php --key=YOUR_ADMIN_KEY >/dev/null 2>&1
```
Now anything queued (including scheduled `send_at` times) goes out automatically.

## 6. Wire the website "Apply" form
Point your job-posting Apply form to POST to `apply.php`:
```html
<form action="https://bluepeakrecruitments.com/mail/apply.php" method="post">
  <input name="first_name" required>
  <input name="last_name">
  <input type="email" name="email" required>
  <input type="hidden" name="role_applied" value="Customer Service Representative (Remote)">
  <button type="submit">Apply</button>
</form>
```
On submit it creates the applicant and auto-queues `application_received` — the
cron sends it within 5 minutes. (For instant sends, the form can also hit
send.php, but cron is simpler and safer.)

## 7. The rest of the flow
Queue the other stages from admin.php as candidates progress:
- `ai_screen_invite` — set `booking_url` to the Calendly link
- `offer_letter` — set `role_title`, `client_company`, `salary` ($20.00 per hour),
  `hours` (20–40 hours per week), `employment_type`, `location`, `offer_url`, `expires_date`
- `id_verification` — set `verify_url` to the in-house Persona link (valid 24h),
  plus `role_title` and `client_company`
- `rejection` — for unsuccessful candidates

## Deliverability (do this before bulk sending)
In cPanel → **Email Deliverability**, make sure SPF and DKIM are green for the
domain. Send a test to https://mail-tester.com and aim for 9+/10.

## Notes
- `daily_cap`, `batch_size`, and `throttle_seconds` in config.php keep you under
  your host's mail limits — check your hosting plan's hourly send limit and set
  `daily_cap` below it.
- PHPMailer is bundled in `lib/PHPMailer/` — no Composer needed.
- To host the offer-signing and Persona pages on this same domain later, the PHP
  ports of those pages slot in alongside these files. Ask when you're ready.
