submitContactForm
A Next.js server action that validates and processes contact form submissions, sending emails via the Resend API.Parameters
The previous form state from React’s
useFormState hook.The form data containing the contact information.Expected fields:
email(string): User’s email address (must be valid email format)service(string): Selected service (minimum 1 character)message(string): Contact message (minimum 10 characters)
Returns
Type Definition
src/app/actions.ts
Validation Schema
The function uses Zod for validation with the following schema:src/app/actions.ts
Usage Example
Error Handling
The function returns different error messages for various failure scenarios:- Invalid email: “Por favor, introduce un email válido.”
- Missing service: “Por favor, selecciona un servicio.”
- Message too short: “El mensaje debe tener al menos 10 caracteres.”
- Validation error: “Error de validación.”
- Configuration error: Missing or invalid RESEND_API_KEY
- API error: “Ocurrió un error inesperado al enviar el formulario.”
Environment Variables
Resend API key for sending emails. Must start with
re_.Success Response
On successful submission:Source Code
See the full implementation atsrc/app/actions.ts:29-105