user1724434 user1724434 - 5 months ago 37
PHP Question

WordPress editor ignoring line breaks

I am using a plugin that was custom made for a unique registration website. There's a setting page in the WP dashboard where the admin can write the registration confirmation email sent to the users and this page uses the default wp-editor (I think it's TinyMCE).

I confirmed this because the plugin's setting.php has the following loop

wp_editor( $content, $editor_id );

The problem is that while the editor works fine on Posts and Pages, when the email is sent out from my plugin's setting page that uses the same editor, it is delivered without line breaks.

I have tried using the editor in text mode to create a line break with
<br />
but they don't work either and upon saving the change, the html tags get translated into rich text i.e
<br />
turns to
&lt;br &gt;

This is what my send mail function looks like in the plugin:

function SendMails($Data){
$To = $Data['To'];
$Subject = $Data['Subject'];
$Sender = $Data['SenderName'];
$From = 'support@'.$_SERVER['SERVER_NAME'];
$Body = $Data['Body'];
$Attachments = $Data['Attachments'];

$recipients = array($To);
$headers[] = "From: $Sender <$From>" . "\r\n";
$headers[] = "Content-Type: text/html";
$subj = $Subject;
$SendMail = wp_mail( $recipients, $subj, $Body, $headers, $Attachments );
return $SendMail;

P.S. All other WP emails are delivered correctly with line breaks.

Any idea what the issue could be and/or how to fix it?


use this code to convert breaks to

$Body = preg_replace("/\r\n|\r|\n/",'<br/>',$Data['Body']);