fix: connect EmailService to contact form handler
The contact form was logging submissions but never actually sending emails. This commit: - Adds EmailService field to CVHandler - Initializes EmailService in main.go with SMTP config - Calls SendContactForm in HandleContact handler - Updates all test files to pass nil for emailService parameter
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
uimodel "github.com/juanatsap/cv-site/internal/models/ui"
|
||||
"github.com/juanatsap/cv-site/internal/services"
|
||||
)
|
||||
|
||||
// ==============================================================================
|
||||
@@ -81,14 +82,33 @@ func (h *CVHandler) HandleContact(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Log the contact form submission (in production, send email or save to database)
|
||||
// Log the contact form submission
|
||||
log.Printf("Contact form submission from %s (IP: %s)", formData.Email, getClientIP(r))
|
||||
log.Printf(" Name: %s, Company: %s", formData.Name, formData.Company)
|
||||
log.Printf(" Subject: %s", formData.Subject)
|
||||
log.Printf(" Message length: %d characters", len(formData.Message))
|
||||
|
||||
// TODO: Implement actual email sending or database storage here
|
||||
// For now, we just log and return success
|
||||
// Send email via EmailService
|
||||
if h.emailService != nil {
|
||||
emailData := &services.ContactFormData{
|
||||
Email: formData.Email,
|
||||
Name: formData.Name,
|
||||
Company: formData.Company,
|
||||
Subject: formData.Subject,
|
||||
Message: formData.Message,
|
||||
IP: getClientIP(r),
|
||||
Time: time.Now(),
|
||||
}
|
||||
|
||||
if err := h.emailService.SendContactForm(emailData); err != nil {
|
||||
log.Printf("ERROR sending contact email: %v", err)
|
||||
h.renderContactError(w, r, "Failed to send message. Please try again later.")
|
||||
return
|
||||
}
|
||||
log.Printf("Contact email sent successfully to configured recipient")
|
||||
} else {
|
||||
log.Printf("WARNING: Email service not configured, skipping email send")
|
||||
}
|
||||
|
||||
// Render success response
|
||||
h.renderContactSuccess(w, r, lang)
|
||||
|
||||
Reference in New Issue
Block a user