0

I have a smart text editor script on my website so I can email users about updates and I can edit the text, eg. Bold, underlined, basically like the stack overflow text area with all the options. I have it configured so that once I send it, it will add whatever I've written in the textarea into an email and send it to whoever I choose. Problem is the email then shows all of the
characters? Half of the email is script and it looks so unprofessional? Here are the codes, I'm wondering if there is a way to stop all of the codes from being shown in the email?

<textarea name="email_body" style="width: 540px; height: 200px;" required="required">
Enter email text here...
</textarea>

 <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js" </script> <script type="text/javascript">
//<![CDATA[
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
//]]>
</script>


// Let's mail all users!
$subject = $sub;
$message = "Dear $firstname 

$body


http://basecentre.co.uk, please do not reply directly to this email...!";

mail($emails, $subject, $message, "From: BaseCentre Updates<admin@basecentre.co.uk>\nX-Mailer: PHP/" . phpversion());

The email sends well and everything works apart from it shows the code instead of initiates it? Any ideas? Thanks!

AidanPT
  • 185
  • 1
  • 3
  • 12
  • So you're basically looking to use [`strip_tags()`](http://www.php.net/strip_tags) on your $body ? – Tularis Mar 27 '14 at 11:42
  • What is the name of the text-editor that you are using and in which environment (Windows/Mac/Linux etc). – Vagabond Mar 27 '14 at 11:43
  • I'm looking to not display the code in the email for the users to see? and the editor is called http://nicedit.com/ – AidanPT Mar 27 '14 at 11:44
  • I haven't downloaded it, I am using the code that's on their homepage? – AidanPT Mar 27 '14 at 11:44
  • Or do you want the HTML in your email to actually be seen as _parsed_ html in the mailprogram of the recipient? If so, you'll need to add a header stating that the `Content-type` of the email is `text/html` – Tularis Mar 27 '14 at 11:45
  • I have no idea what that means, I'm pretty new to this kind of stuff. I'd like them to see the message how I type it like with new paragraphs and stuff, but its showing in one block and every time I press enter it shows breaks? – AidanPT Mar 27 '14 at 11:45

1 Answers1

0

Use html2text (source; example HTML to text), licensed under the Eclipse Public License. It uses PHP's DOM methods to load from HTML, and then iterates over the resulting DOM to extract plain text. Usage:

$text = convert_html_to_text($html);

for more info check this link

Converting HTML to plain text in PHP for e-mail

Community
  • 1
  • 1
Dexter
  • 1,804
  • 4
  • 24
  • 53