I am using the Mail::send service to send an email from a contact form. The body of the email is HTML, provided with the richeditor. I have a template 'my.plugin::mail.default':
subject = "Overwritten"
==
<p>Hi {{ name }},</p>
{{message_body | raw}}
<p>This email was sent using formatting (HTML)</p>
and the code to send is like this:
$data=post();
$vars = [
'subject' => $data['subject'],
'message_body' =>$data['message'],
'name'=>'STB '
];
Mail::send('my.plugin::mail.default', $vars, function ($message) use ($vars) {
$message->to("[email protected]");
$message->subject($vars['subject']);
});
Email sent this way has the HTML message striped and only first tag (ex: <p>abc<p/>) is sent.
After many test, I figured out that when the HTML has the new-line character \n (as var $html below), Mail::send sends the message correctly. However, when the HTML hasn't the new-line character (as var $html_richeditor below), then it is cut.
$html = '<p>Aenean finibus erat eget maximus luctus. Phasellus vitae lectus dolor. Morbi convallis ex et turpis porttitor mattis morbi convallis ex et turpis porttitor mattis</p>
<p>Proin porta, nibh eget elementum aliquet, metus elit viverra nisi, vitae ullamcorper elit eros ut urna.</p>
<br/><br><p>Morbi convallis ex et turpis porttitor mattis.</p>';
$html_richeditor = "<p>Aenean finibus erat eget maximus luctus. Phasellus vitae lectus dolor. Morbi convallis ex et turpis porttitor mattis morbi convallis ex et turpis porttitor mattis</p><p>Proin porta, nibh eget elementum aliquet, metus elit viverra nisi, vitae ullamcorper elit eros ut urna.</p><p><br></p><p><br></p><p>Morbi convallis ex et turpis porttitor mattis.</p>";
Any idea how I can send the whole HTML from the richeditor? Should I config something in the richeditor or in the Mail?
I have debugged a lot and found out that HTML was parsed by
Markdownand it was not linking that single line stuff and just keep the firsttag.It is important to note that the Markdown parser will only accept one HTML node per line.
Ref: https://docs.octobercms.com/2.x/services/parser.html#using-html-in-markdown
So we need to make our HTML like one node per line. we can just append
\nto all tag's ending>bracket so it will persist duringMarkdownparsing.if any doubts please comment.