changed contact form reply_to and response html
This commit is contained in:
@@ -15,7 +15,7 @@ type ContactController struct {
|
||||
EmailService *services.EmailService
|
||||
}
|
||||
type contactData struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Email string `form:"REPLY_TO" validate:"required,email"`
|
||||
Name string `form:"name"`
|
||||
Message string `form:"message" validate:"required"`
|
||||
Honeypot string `form:"username" validate:"eq="`
|
||||
@@ -32,16 +32,19 @@ func (cc *ContactController) RelayContactRequest(c *gin.Context) {
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(msgData); err != nil {
|
||||
logger.Error.Printf("Couldn't validate contact form data: %v", err)
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{"error": "Couldn't validate contact form data"})
|
||||
logger.Error.Printf("Couldn't validate contact form data: %#v: %v", msgData, err)
|
||||
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Error": "Form submission failed. Please try again."})
|
||||
// c.JSON(http.StatusNotAcceptable, gin.H{"error": "Couldn't validate contact form data"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := cc.EmailService.RelayContactFormMessage(msgData.Email, msgData.Name, msgData.Message); err != nil {
|
||||
logger.Error.Printf("Couldn't send contact message mail: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Couldn't send mail"})
|
||||
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Error": "Form submission failed. Please try again."})
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": "Couldn't send mail"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusAccepted, "Your message has been sent")
|
||||
// c.JSON(http.StatusAccepted, "Your message has been sent")
|
||||
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Success": true})
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func getBaseRequest() *url.Values {
|
||||
return &url.Values{
|
||||
"username": {""},
|
||||
"name": {"My-First and-Last-Name"},
|
||||
"email": {"name@domain.de"},
|
||||
"REPLY_TO": {"name@domain.de"},
|
||||
"message": {"My message to the world"},
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func getContactData() []RelayContactRequestTest {
|
||||
Assert: false,
|
||||
Input: *customizeRequest(
|
||||
map[string]string{
|
||||
"email": "",
|
||||
"REPLY_TO": "",
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -125,7 +125,7 @@ func getContactData() []RelayContactRequestTest {
|
||||
Assert: false,
|
||||
Input: *customizeRequest(
|
||||
map[string]string{
|
||||
"email": "novalid#email.de",
|
||||
"REPLY_TO": "novalid#email.de",
|
||||
}),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -21,11 +21,14 @@ func NewEmailService(host string, port int, username string, password string) *E
|
||||
return &EmailService{dialer: dialer}
|
||||
}
|
||||
|
||||
func (s *EmailService) SendEmail(to string, subject string, body string) error {
|
||||
func (s *EmailService) SendEmail(to string, subject string, body string, replyTo string) error {
|
||||
msg := gomail.NewMessage()
|
||||
msg.SetHeader("From", s.dialer.Username)
|
||||
msg.SetHeader("To", to)
|
||||
msg.SetHeader("Subject", subject)
|
||||
if replyTo != "" {
|
||||
msg.SetHeader("REPLY_TO", replyTo)
|
||||
}
|
||||
msg.SetBody("text/html", body)
|
||||
|
||||
if err := s.dialer.DialAndSend(msg); err != nil {
|
||||
@@ -76,7 +79,7 @@ func (s *EmailService) SendVerificationEmail(user *models.User, token *string) e
|
||||
logger.Error.Print("Couldn't send verification mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(user.Email, subject, body)
|
||||
return s.SendEmail(user.Email, subject, body, "")
|
||||
|
||||
}
|
||||
|
||||
@@ -106,7 +109,7 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error {
|
||||
logger.Error.Print("Couldn't send welcome mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(user.Email, subject, body)
|
||||
return s.SendEmail(user.Email, subject, body, "")
|
||||
}
|
||||
|
||||
func (s *EmailService) SendRegistrationNotification(user *models.User) error {
|
||||
@@ -151,7 +154,7 @@ func (s *EmailService) SendRegistrationNotification(user *models.User) error {
|
||||
logger.Error.Print("Couldn't send admin notification mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(config.Recipients.UserRegistration, subject, body)
|
||||
return s.SendEmail(config.Recipients.UserRegistration, subject, body, "")
|
||||
}
|
||||
|
||||
func (s *EmailService) RelayContactFormMessage(sender string, name string, message string) error {
|
||||
@@ -170,5 +173,5 @@ func (s *EmailService) RelayContactFormMessage(sender string, name string, messa
|
||||
logger.Error.Print("Couldn't send contact form message mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(config.Recipients.ContactForm, subject, body)
|
||||
return s.SendEmail(config.Recipients.ContactForm, subject, body, sender)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user