質問編集履歴
2
試した内容を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,6 +60,186 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
### 追記
|
63
|
+
### 追記1
|
64
64
|
|
65
65
|
送信されるメールはHTMLメールです。
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
### 追記2
|
70
|
+
|
71
|
+
下記のようにプラグインのソースコード(EmailNotification.php)に直接書いてみたら動作しました。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```php
|
76
|
+
|
77
|
+
public function notify($notification, $submittedData, $form, $entryId = false)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
$headers = $this->getHeaders($notification);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
$attachments = $this->app->applyFilters(
|
86
|
+
|
87
|
+
'fluentform_filter_email_notification',
|
88
|
+
|
89
|
+
isset($notification['attachments']) ? $notification['attachments'] : [],
|
90
|
+
|
91
|
+
$notification,
|
92
|
+
|
93
|
+
$form,
|
94
|
+
|
95
|
+
$submittedData
|
96
|
+
|
97
|
+
);
|
98
|
+
|
99
|
+
// 置換処理 3行追加
|
100
|
+
|
101
|
+
$notification['message'] = str_replace ("\n", "<br/>", $notification['message']);
|
102
|
+
|
103
|
+
$notification['message'] = str_replace ("\r\n", "<br/>", $notification['message']);
|
104
|
+
|
105
|
+
$emailBody = $notification['message'];
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
$isSendAsPlain = ArrayHelper::get($notification, 'asPlainText') == 'yes';
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
if (!apply_filters('fluenform_send_plain_html_email', $isSendAsPlain, $form, $notification)) {
|
114
|
+
|
115
|
+
$emailBody = $this->getEmailWithTemplate($emailBody, $form, $notification);
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
if( ArrayHelper::get($notification, 'sendTo.type') == 'field' && !empty($notification['sendTo']['field']) ) {
|
122
|
+
|
123
|
+
$notification['sendTo']['email'] = ArrayHelper::get($submittedData, $notification['sendTo']['field']);
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
if ( !$notification['sendTo']['email'] || !$notification['subject'] ) {
|
130
|
+
|
131
|
+
do_action('ff_log_data', [
|
132
|
+
|
133
|
+
'parent_source_id' => $form->id,
|
134
|
+
|
135
|
+
'source_type' => 'submission_item',
|
136
|
+
|
137
|
+
'source_id' => $entryId,
|
138
|
+
|
139
|
+
'component' => 'EmailNotification',
|
140
|
+
|
141
|
+
'status' => 'error',
|
142
|
+
|
143
|
+
'title' => 'Email sending skipped',
|
144
|
+
|
145
|
+
'description' => "Email skipped to send because email may not valid.<br />Subject: {$notification['subject']}. <br/>Email: " . $notification['sendTo']['email'],
|
146
|
+
|
147
|
+
]);
|
148
|
+
|
149
|
+
return false;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
if ($entryId) {
|
156
|
+
|
157
|
+
do_action('ff_log_data', [
|
158
|
+
|
159
|
+
'parent_source_id' => $form->id,
|
160
|
+
|
161
|
+
'source_type' => 'submission_item',
|
162
|
+
|
163
|
+
'source_id' => $entryId,
|
164
|
+
|
165
|
+
'component' => 'EmailNotification',
|
166
|
+
|
167
|
+
'status' => 'info',
|
168
|
+
|
169
|
+
'title' => 'Email sending initiated',
|
170
|
+
|
171
|
+
'description' => "Email Notification broadcasted to " . $notification['sendTo']['email'] . ".<br />Subject: {$notification['subject']}",
|
172
|
+
|
173
|
+
]);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
/*
|
178
|
+
|
179
|
+
* Inline email logger. It will work fine hopefully
|
180
|
+
|
181
|
+
*/
|
182
|
+
|
183
|
+
add_action('wp_mail_failed', function ($error) use ($notification, $form, $entryId) {
|
184
|
+
|
185
|
+
$failedMailSubject = ArrayHelper::get($error->error_data, 'wp_mail_failed.subject');
|
186
|
+
|
187
|
+
if ($failedMailSubject == $notification['subject']) {
|
188
|
+
|
189
|
+
$reason = $error->get_error_message();
|
190
|
+
|
191
|
+
do_action('ff_log_data', [
|
192
|
+
|
193
|
+
'parent_source_id' => $form->id,
|
194
|
+
|
195
|
+
'source_type' => 'submission_item',
|
196
|
+
|
197
|
+
'source_id' => $entryId,
|
198
|
+
|
199
|
+
'component' => 'EmailNotification',
|
200
|
+
|
201
|
+
'status' => 'failed',
|
202
|
+
|
203
|
+
'title' => 'Email sending failed',
|
204
|
+
|
205
|
+
'description' => "Email Notification failed to sent.<br />Subject: {$notification['subject']}. <br/>Reason: " . $reason,
|
206
|
+
|
207
|
+
]);
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}, 10, 1);
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
$isMailSentSuccessfully = wp_mail(
|
218
|
+
|
219
|
+
$notification['sendTo']['email'],
|
220
|
+
|
221
|
+
$notification['subject'],
|
222
|
+
|
223
|
+
$emailBody,
|
224
|
+
|
225
|
+
$headers,
|
226
|
+
|
227
|
+
$attachments
|
228
|
+
|
229
|
+
);
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
return $isMailSentSuccessfully;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
同じようにfunctions.phpに書いてみたのですが、そうすると改行されません。
|
240
|
+
|
241
|
+
「functions.phpに書いた時はそもそもメール本文をとってきてないのでは?」と思い、ネットで調べてログファイルに出力してみましたが、何も出力されませんでした。
|
242
|
+
|
243
|
+
functions.phpの時は改行されないのは何が原因なのでしょうか?
|
244
|
+
|
245
|
+
ご教示いただければ幸いです。
|
1
送信されるメールについて追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -57,3 +57,9 @@
|
|
57
57
|
|
58
58
|
|
59
59
|
よろしくお願いします。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
### 追記
|
64
|
+
|
65
|
+
送信されるメールはHTMLメールです。
|