diff --git a/README.md b/README.md index 342c03a6..2135d703 100644 --- a/README.md +++ b/README.md @@ -273,13 +273,11 @@ If you prefer another host you can explore alternatives: ## Setup Admin Emailer -- Optional -SaaS Starter includes an admin emailer for sending yourself email notifications when important events happen, such as a new user creating their profile. This let's you monitor your app and respond to users without watching the database. +SaaS Starter includes an admin emailer for sending yourself email notifications when important events happen. This let's you monitor your app and respond to users without watching the database. -Provide email SMTP credientials in your environment variables: `PRIVATE_SMTP_HOST`, `PRIVATE_SMTP_PORT`, `PRIVATE_SMTP_USER`, `PRIVATE_SMTP_PASS`. You can use any SMTP providers such as Gmail, Sendgrid, AWS SES, Resend, or Mailgun. +If you setup the admin emailer, it will email you when users create their profile or the 'Contact Us' form is submitted. You can add additional calls to sendAdminEmail() for any other events you want to monitor. -Set the email address which admil emails will be sent to in `PRIVATE_ADMIN_EMAIL`. - -You can add additional calls to sendAdminEmail() for any other events you want to monitor. +To setup, provide email SMTP credientials in your environment variables: `PRIVATE_SMTP_HOST`, `PRIVATE_SMTP_PORT`, `PRIVATE_SMTP_USER`, `PRIVATE_SMTP_PASS`. You can use any SMTP providers such as Gmail, Sendgrid, AWS SES, Resend, or Mailgun. Then set the email address to which admin emails will be sent in `PRIVATE_ADMIN_EMAIL`. ## Add Your Content diff --git a/package.json b/package.json index d5fdbcf0..f2491fcd 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,14 @@ "@supabase/auth-ui-svelte": "^0.2.9", "@supabase/supabase-js": "^2.33.0", "@types/nodemailer": "^6.4.15", - "nodemailer": "^6.9.14", "stripe": "^13.3.0" + }, + "peerDependencies": { + "nodemailer": "^6.9.14" + }, + "peerDependenciesMeta": { + "nodemailer": { + "optional": true + } } } diff --git a/src/routes/(marketing)/contact_us/+page.server.ts b/src/routes/(marketing)/contact_us/+page.server.ts index ffaceb4a..681c4780 100644 --- a/src/routes/(marketing)/contact_us/+page.server.ts +++ b/src/routes/(marketing)/contact_us/+page.server.ts @@ -1,4 +1,5 @@ import { fail } from "@sveltejs/kit" +import { sendAdminEmail } from "$lib/admin_mailer.js" /** @type {import('./$types').Actions} */ export const actions = { @@ -67,5 +68,11 @@ export const actions = { if (insertError) { return fail(500, { errors: { _: "Error saving" } }) } + + // Send email to admin + sendAdminEmail({ + subject: "New contact request", + body: `New contact request from ${firstName} ${lastName}.\n\nEmail: ${email}\n\nPhone: ${phone}\n\nCompany: ${company}\n\nMessage: ${message}`, + }) }, }