実現したいこと
WordPressもプログラミングも理解できていないところが多いのですが、現在WordPressを利用したサイトを運用しています。
「WP Fluentform」というプラグインを用いてお問い合わせフォームを作ったのですが、お問い合わせフォームから送信されるメール本文が改行されず、1行になって表示されてしまいます。
メール本文の改行を消さずに入力した内容通りに送信したいです。
試したこと
少し前まではfunctions.phpに下記のソースコードを追加したら改行できていました。
php
1function fluentform_filter_email_new_line ($notification, $data, $form, $entryId) { 2 $notification['message'] = str_replace ("\n", "<br/>", $notification['message']); 3 $notification['message'] = str_replace ("\r\n", "<br/>", $notification['message']); 4 return $notification; 5} 6add_filter('fluentform_filter_email_notification','fluentform_filter_email_new_line',10,4);
いつから改行していなかったのかはまだわかっていないのですが、おそらくプラグインの更新を行ってからではないかと考えています。
データベースにはちゃんと改行された状態でお問い合わせ内容が入っていました。
他のプラグインが影響しているのかと思い、文字コードやメール送受信に影響しそうなプラグインを停止してみたりしたのですが、うまくいきませんでした。
他に何をすればいいのかわからず。。。
お助けください。
補足情報
WordPressのバージョンは5.3.2です。
よろしくお願いします。
追記1
送信されるメールはHTMLメールです。
追記2
下記のようにプラグインのソースコード(EmailNotification.php)に直接書いてみたら動作しました。
php
1public function notify($notification, $submittedData, $form, $entryId = false) 2 { 3 $headers = $this->getHeaders($notification); 4 5 $attachments = $this->app->applyFilters( 6 'fluentform_filter_email_notification', 7 isset($notification['attachments']) ? $notification['attachments'] : [], 8 $notification, 9 $form, 10 $submittedData 11 ); 12 // 置換処理 3行追加 13 $notification['message'] = str_replace ("\n", "<br/>", $notification['message']); 14 $notification['message'] = str_replace ("\r\n", "<br/>", $notification['message']); 15 $emailBody = $notification['message']; 16 17 $isSendAsPlain = ArrayHelper::get($notification, 'asPlainText') == 'yes'; 18 19 if (!apply_filters('fluenform_send_plain_html_email', $isSendAsPlain, $form, $notification)) { 20 $emailBody = $this->getEmailWithTemplate($emailBody, $form, $notification); 21 } 22 23 if( ArrayHelper::get($notification, 'sendTo.type') == 'field' && !empty($notification['sendTo']['field']) ) { 24 $notification['sendTo']['email'] = ArrayHelper::get($submittedData, $notification['sendTo']['field']); 25 } 26 27 if ( !$notification['sendTo']['email'] || !$notification['subject'] ) { 28 do_action('ff_log_data', [ 29 'parent_source_id' => $form->id, 30 'source_type' => 'submission_item', 31 'source_id' => $entryId, 32 'component' => 'EmailNotification', 33 'status' => 'error', 34 'title' => 'Email sending skipped', 35 'description' => "Email skipped to send because email may not valid.<br />Subject: {$notification['subject']}. <br/>Email: " . $notification['sendTo']['email'], 36 ]); 37 return false; 38 } 39 40 if ($entryId) { 41 do_action('ff_log_data', [ 42 'parent_source_id' => $form->id, 43 'source_type' => 'submission_item', 44 'source_id' => $entryId, 45 'component' => 'EmailNotification', 46 'status' => 'info', 47 'title' => 'Email sending initiated', 48 'description' => "Email Notification broadcasted to " . $notification['sendTo']['email'] . ".<br />Subject: {$notification['subject']}", 49 ]); 50 51 /* 52 * Inline email logger. It will work fine hopefully 53 */ 54 add_action('wp_mail_failed', function ($error) use ($notification, $form, $entryId) { 55 $failedMailSubject = ArrayHelper::get($error->error_data, 'wp_mail_failed.subject'); 56 if ($failedMailSubject == $notification['subject']) { 57 $reason = $error->get_error_message(); 58 do_action('ff_log_data', [ 59 'parent_source_id' => $form->id, 60 'source_type' => 'submission_item', 61 'source_id' => $entryId, 62 'component' => 'EmailNotification', 63 'status' => 'failed', 64 'title' => 'Email sending failed', 65 'description' => "Email Notification failed to sent.<br />Subject: {$notification['subject']}. <br/>Reason: " . $reason, 66 ]); 67 } 68 }, 10, 1); 69 } 70 71 $isMailSentSuccessfully = wp_mail( 72 $notification['sendTo']['email'], 73 $notification['subject'], 74 $emailBody, 75 $headers, 76 $attachments 77 ); 78 79 return $isMailSentSuccessfully; 80 }
同じようにfunctions.phpに書いてみたのですが、そうすると改行されません。
「functions.phpに書いた時はそもそもメール本文をとってきてないのでは?」と思い、ネットで調べてログファイルに出力してみましたが、何も出力されませんでした。
functions.phpの時は改行されないのは何が原因なのでしょうか?
ご教示いただければ幸いです。