@@ -19,7 +19,6 @@ class FormEmailNotification extends Notification implements ShouldQueue
19
19
20
20
public FormSubmitted $ event ;
21
21
public string $ mailer ;
22
- private array $ formattedData ;
23
22
24
23
/**
25
24
* Create a new notification instance.
@@ -30,7 +29,6 @@ public function __construct(FormSubmitted $event, private $integrationData, stri
30
29
{
31
30
$ this ->event = $ event ;
32
31
$ this ->mailer = $ mailer ;
33
- $ this ->formattedData = $ this ->formatSubmissionData ();
34
32
}
35
33
36
34
/**
@@ -54,7 +52,7 @@ public function toMail($notifiable)
54
52
{
55
53
return (new MailMessage ())
56
54
->mailer ($ this ->mailer )
57
- ->replyTo ($ this ->getReplyToEmail ($ notifiable -> routes [ ' mail ' ] ))
55
+ ->replyTo ($ this ->getReplyToEmail ($ this -> event -> form -> creator -> email ))
58
56
->from ($ this ->getFromEmail (), $ this ->getSenderName ())
59
57
->subject ($ this ->getSubject ())
60
58
->withSymfonyMessage (function (Email $ message ) {
@@ -63,13 +61,15 @@ public function toMail($notifiable)
63
61
->markdown ('mail.form.email-notification ' , $ this ->getMailData ());
64
62
}
65
63
66
- private function formatSubmissionData (): array
64
+ private function formatSubmissionData ($ createLinks = true ): array
67
65
{
68
66
$ formatter = (new FormSubmissionFormatter ($ this ->event ->form , $ this ->event ->data ))
69
- ->createLinks ()
70
67
->outputStringsOnly ()
71
68
->useSignedUrlForFiles ();
72
69
70
+ if ($ createLinks ) {
71
+ $ formatter ->createLinks ();
72
+ }
73
73
if ($ this ->integrationData ->include_hidden_fields_submission_data ?? false ) {
74
74
$ formatter ->showHiddenFields ();
75
75
}
@@ -98,27 +98,25 @@ private function getSenderName(): string
98
98
private function getReplyToEmail ($ default ): string
99
99
{
100
100
$ replyTo = $ this ->integrationData ->reply_to ?? null ;
101
-
102
101
if ($ replyTo ) {
103
102
$ parsedReplyTo = $ this ->parseReplyTo ($ replyTo );
104
103
if ($ parsedReplyTo && $ this ->validateEmail ($ parsedReplyTo )) {
105
104
return $ parsedReplyTo ;
106
105
}
107
106
}
108
-
109
- return $ this ->getRespondentEmail () ?? $ default ;
107
+ return $ default ;
110
108
}
111
109
112
110
private function parseReplyTo (string $ replyTo ): ?string
113
111
{
114
- $ parser = new MentionParser ($ replyTo , $ this ->formattedData );
112
+ $ parser = new MentionParser ($ replyTo , $ this ->formatSubmissionData ( false ) );
115
113
return $ parser ->parse ();
116
114
}
117
115
118
116
private function getSubject (): string
119
117
{
120
118
$ defaultSubject = 'New form submission ' ;
121
- $ parser = new MentionParser ($ this ->integrationData ->subject ?? $ defaultSubject , $ this ->formattedData );
119
+ $ parser = new MentionParser ($ this ->integrationData ->subject ?? $ defaultSubject , $ this ->formatSubmissionData ( false ) );
122
120
return $ parser ->parse ();
123
121
}
124
122
@@ -150,7 +148,7 @@ private function getMailData(): array
150
148
{
151
149
return [
152
150
'emailContent ' => $ this ->getEmailContent (),
153
- 'fields ' => $ this ->formattedData ,
151
+ 'fields ' => $ this ->formatSubmissionData () ,
154
152
'form ' => $ this ->event ->form ,
155
153
'integrationData ' => $ this ->integrationData ,
156
154
'noBranding ' => $ this ->event ->form ->no_branding ,
@@ -160,7 +158,7 @@ private function getMailData(): array
160
158
161
159
private function getEmailContent (): string
162
160
{
163
- $ parser = new MentionParser ($ this ->integrationData ->email_content ?? '' , $ this ->formattedData );
161
+ $ parser = new MentionParser ($ this ->integrationData ->email_content ?? '' , $ this ->formatSubmissionData () );
164
162
return $ parser ->parse ();
165
163
}
166
164
@@ -170,26 +168,6 @@ private function getEncodedSubmissionId(): ?string
170
168
return $ submissionId ? Hashids::encode ($ submissionId ) : null ;
171
169
}
172
170
173
- private function getRespondentEmail (): ?string
174
- {
175
- $ emailFields = ['email ' , 'e-mail ' , 'mail ' ];
176
-
177
- foreach ($ this ->formattedData as $ field => $ value ) {
178
- if (in_array (strtolower ($ field ), $ emailFields ) && $ this ->validateEmail ($ value )) {
179
- return $ value ;
180
- }
181
- }
182
-
183
- // If no email field found, search for any field containing a valid email
184
- foreach ($ this ->formattedData as $ value ) {
185
- if ($ this ->validateEmail ($ value )) {
186
- return $ value ;
187
- }
188
- }
189
-
190
- return null ;
191
- }
192
-
193
171
public static function validateEmail ($ email ): bool
194
172
{
195
173
return (bool )filter_var ($ email , FILTER_VALIDATE_EMAIL );
0 commit comments