Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 9816333

Browse files
author
Patrik Kozak
committed
feat: adds email-from-name & reply-to-name fields to Emails
1 parent 9260769 commit 9816333

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/collections/FormSubmissions/hooks/sendEmail.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ const sendEmail = async (beforeChangeData: any, formConfig: FormConfig) => {
4646
subject,
4747
emailTo,
4848
emailFrom,
49+
emailFromName,
4950
replyTo: emailReplyTo,
51+
replyToName,
5052
} = email;
5153

5254
const to = replaceDoubleCurlys(emailTo, submissionData);
53-
const from = replaceDoubleCurlys(emailFrom, submissionData);
54-
const replyTo = replaceDoubleCurlys(emailReplyTo || emailFrom, submissionData);
55+
const from = replaceDoubleCurlys(emailFromName ? `"${emailFromName}" ` + emailFrom : emailFrom, submissionData);
56+
const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData);
5557

5658
if (to && from) {
5759
return ({

src/collections/Forms/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ export const generateFormCollection = (formConfig: FormConfig): CollectionConfig
156156
},
157157
{
158158
type: 'text',
159-
name: 'emailFrom',
160-
label: 'Email From',
159+
name: 'bcc',
160+
label: 'BCC',
161161
admin: {
162162
width: '50%',
163-
placeholder: 'Email Recipient <{{email}}>',
164163
},
165164
},
166165
],
@@ -178,8 +177,30 @@ export const generateFormCollection = (formConfig: FormConfig): CollectionConfig
178177
},
179178
{
180179
type: 'text',
181-
name: 'bcc',
182-
label: 'BCC',
180+
name: 'replyToName',
181+
label: 'Reply To Name',
182+
admin: {
183+
width: '50%',
184+
},
185+
},
186+
],
187+
},
188+
{
189+
type: 'row',
190+
fields: [
191+
{
192+
type: 'text',
193+
name: 'emailFrom',
194+
label: 'Email From',
195+
admin: {
196+
width: '50%',
197+
placeholder: 'Email Recipient <{{email}}>',
198+
},
199+
},
200+
{
201+
type: 'text',
202+
name: 'emailFromName',
203+
label: 'Email From Name',
183204
admin: {
184205
width: '50%',
185206
},

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ export type FormFieldBlock = TextField | SelectField | EmailField | StateField |
144144
export type Email = {
145145
emailTo: string
146146
emailFrom: string
147+
emailFromName?: string
147148
bcc?: string
148149
replyTo?: string
150+
replyToName?: string
149151
subject: string
150152
message?: any // TODO: configure rich text type
151153
}

0 commit comments

Comments
 (0)