|
| 1 | +'use server'; |
| 2 | + |
| 3 | +import { Resend } from 'resend'; |
| 4 | + |
| 5 | +const resend = new Resend(process.env.RESEND_API_KEY); |
| 6 | + |
| 7 | +export async function sendContactAction(formData: FormData) { |
| 8 | + const name = formData.get('name') as string; |
| 9 | + const email = formData.get('email') as string; |
| 10 | + const message = formData.get('message') as string; |
| 11 | + |
| 12 | + if (!name || !email || !message) { |
| 13 | + return { error: 'All fields are required for transmission.' }; |
| 14 | + } |
| 15 | + |
| 16 | + try { |
| 17 | + const { data, error } = await resend.emails.send({ |
| 18 | + from: 'Contact Signal <onboarding@resend.dev>', |
| 19 | + to: 'fairshare4u@gmail.com', |
| 20 | + subject: `New Signal from ${name}`, |
| 21 | + replyTo: email, |
| 22 | + html: ` |
| 23 | + <div style="font-family: sans-serif; padding: 20px; color: #333; background: #fafafa; border-radius: 12px;"> |
| 24 | + <h2 style="color: #7c3aed; margin-bottom: 4px;">Incoming Transmission</h2> |
| 25 | + <p style="font-size: 12px; color: #666; margin-bottom: 24px;">Source: ${name} (${email})</p> |
| 26 | + |
| 27 | + <div style="background: white; padding: 20px; border-radius: 8px; border: 1px solid #eee;"> |
| 28 | + <p style="margin: 0; white-space: pre-wrap;">${message}</p> |
| 29 | + </div> |
| 30 | + |
| 31 | + <hr style="border: none; border-top: 1px solid #eee; margin: 24px 0;" /> |
| 32 | + <p style="font-size: 10px; color: #999; text-transform: uppercase; letter-spacing: 1px;">FairShare Signal Protocol v1.0</p> |
| 33 | + </div> |
| 34 | + `, |
| 35 | + }); |
| 36 | + |
| 37 | + if (error) { |
| 38 | + console.error('Resend Contact Error:', error); |
| 39 | + return { error: 'Transmission interrupted. Please try again.' }; |
| 40 | + } |
| 41 | + |
| 42 | + return { success: true }; |
| 43 | + } catch (err) { |
| 44 | + console.error('Contact Action Error:', err); |
| 45 | + return { error: 'System error. Protocol failure.' }; |
| 46 | + } |
| 47 | +} |
0 commit comments