mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
dev day #80
This commit is contained in:
@@ -97,6 +97,43 @@ func (cc *ContactController) SubmitContactForm(c *gin.Context) {
|
||||
UserAgent: ua,
|
||||
})
|
||||
|
||||
// Auto-forward to saved recipients if enabled
|
||||
var set models.Settings
|
||||
if err := cc.DB.First(&set).Error; err == nil && set.ContactForwardEnabled {
|
||||
recipients := make([]string, 0)
|
||||
for _, part := range strings.FieldsFunc(set.ContactForwardList, func(r rune) bool { return r == ',' || r == ';' || r == ' ' || r == '\n' || r == '\t' }) {
|
||||
v := strings.TrimSpace(part)
|
||||
if v != "" {
|
||||
recipients = append(recipients, v)
|
||||
}
|
||||
}
|
||||
if len(recipients) > 0 {
|
||||
forwardData := &email.EmailData{
|
||||
Subject: fmt.Sprintf("Přeposláno: Kontaktní formulář - %s", subject),
|
||||
To: recipients,
|
||||
Template: "contact_form",
|
||||
Data: struct {
|
||||
Name string
|
||||
Email string
|
||||
Subject string
|
||||
Message string
|
||||
Time string
|
||||
IP string
|
||||
Agent string
|
||||
}{
|
||||
Name: name,
|
||||
Email: emailStr,
|
||||
Subject: subject,
|
||||
Message: message,
|
||||
Time: time.Now().Format(time.RFC1123Z),
|
||||
IP: ip,
|
||||
Agent: ua,
|
||||
},
|
||||
}
|
||||
_ = cc.emailService.SendEmail(forwardData)
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Message received", "id": msg.ID})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user