fix: emailJS implementation
This commit is contained in:
4
.env.example
Normal file
4
.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
VITE_EMAILJS_SERVICE_ID=your_service_id_here
|
||||
VITE_EMAILJS_TEMPLATE_ID_ADMIN=your_admin_template_id_here
|
||||
VITE_EMAILJS_TEMPLATE_ID_USER=your_user_template_id_here
|
||||
VITE_EMAILJS_PUBLIC_KEY=your_public_key_here
|
||||
@@ -5,10 +5,11 @@ import { useTranslation } from '../i18n';
|
||||
import { Button, Input, Textarea } from '../components/ui';
|
||||
import styles from './Contact.module.css';
|
||||
|
||||
// EmailJS configuration - replace these with your actual IDs
|
||||
const EMAILJS_SERVICE_ID = 'YOUR_SERVICE_ID';
|
||||
const EMAILJS_TEMPLATE_ID = 'YOUR_TEMPLATE_ID';
|
||||
const EMAILJS_PUBLIC_KEY = 'YOUR_PUBLIC_KEY';
|
||||
// EmailJS configuration
|
||||
const EMAILJS_SERVICE_ID = import.meta.env.VITE_EMAILJS_SERVICE_ID;
|
||||
const EMAILJS_TEMPLATE_ID_ADMIN = import.meta.env.VITE_EMAILJS_TEMPLATE_ID_ADMIN;
|
||||
const EMAILJS_TEMPLATE_ID_USER = import.meta.env.VITE_EMAILJS_TEMPLATE_ID_USER;
|
||||
const EMAILJS_PUBLIC_KEY = import.meta.env.VITE_EMAILJS_PUBLIC_KEY;
|
||||
|
||||
interface FormData {
|
||||
name: string;
|
||||
@@ -70,17 +71,29 @@ export function Contact() {
|
||||
setSubmitStatus('idle');
|
||||
|
||||
try {
|
||||
await emailjs.send(
|
||||
EMAILJS_SERVICE_ID,
|
||||
EMAILJS_TEMPLATE_ID,
|
||||
{
|
||||
const templateParams = {
|
||||
from_name: formData.name,
|
||||
from_email: formData.email,
|
||||
subject: formData.subject,
|
||||
message: formData.message,
|
||||
},
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
// Send to Admin
|
||||
emailjs.send(
|
||||
EMAILJS_SERVICE_ID,
|
||||
EMAILJS_TEMPLATE_ID_ADMIN,
|
||||
templateParams,
|
||||
EMAILJS_PUBLIC_KEY
|
||||
);
|
||||
),
|
||||
// Send Auto-reply to User
|
||||
emailjs.send(
|
||||
EMAILJS_SERVICE_ID,
|
||||
EMAILJS_TEMPLATE_ID_USER,
|
||||
templateParams,
|
||||
EMAILJS_PUBLIC_KEY
|
||||
),
|
||||
]);
|
||||
|
||||
setSubmitStatus('success');
|
||||
setFormData({ name: '', email: '', subject: '', message: '' });
|
||||
|
||||
11
src/vite-env.d.ts
vendored
11
src/vite-env.d.ts
vendored
@@ -1,5 +1,16 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_EMAILJS_SERVICE_ID: string
|
||||
readonly VITE_EMAILJS_TEMPLATE_ID_ADMIN: string
|
||||
readonly VITE_EMAILJS_TEMPLATE_ID_USER: string
|
||||
readonly VITE_EMAILJS_PUBLIC_KEY: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
|
||||
declare module '*.module.css' {
|
||||
const classes: { [key: string]: string };
|
||||
export default classes;
|
||||
|
||||
Reference in New Issue
Block a user