What I am trying to do is enter HTML code into a variable and then pass it along to another script with POST to have it used as the HTML content with PHPmailer. As soon as my HTML code that i paste into the textarea contains double quotes it messes up the data in the variable.
I have been reading about special chars and htmlentities. But how do I process that variable before passing it along with POST? Do i have to use Javascript for that or is there another way?
Here is an abstract of what I currently have:

<form action='mailtest.php' method='post'>
<TEXTAREA name='mainhtmlmessage' rows='100' cols='120'></TEXTAREA>
<input type='submit' value='Next'/>

Hope someone can point me in the right direction.

Recommended Answers

All 7 Replies

$outputdata = htmlentities($inputdata,ENT_QUOTES);

That will do the job for you.

I've used the post method to post html code before and didn't have a problem, but where I had to watch wasn't the page/code doing the posting, but rather the action page receiving the information.

To be fair, it's not quite what you're doing. What I was doing was storing information in a mySQL database and displaying it later. I had html links and images being stored along with their relevant data, but what I did was on the action page I used addslashes() to make it mySQL friendly and then when I displayed it I used stripslashes().

you have to do like,

$input = '<b>some texts..</b>';

$getInput = htmlentities($input);

and on display time you have to decode that input like :

$getOutput = html_entity_decode($getInput);

echo $getOutput;

then you get same html codes,,

hope it will help you

It's not going to convert quotes without the ENT_QUOTES option included. But yes, to convert it back you use html_entity_decode

Hi all,
Thanks for the help. The HTML encoding is necessary.
But what I also found I had to do was do a stripslashes on the data that I was reading from the POST:
$mainhtmlmessage = stripslashes($_POST);

Seems strange. The slashes will be converted along with the rest. How will you know where they should have been?

For example, my address as I live in Scotland contains slashes. Without them, deliveries are often directed to a different (non-existent thankfully) address.

@tiggsy, when you addslashes() doesn't it escape the slashes as well? Then when you strip slashes you should be left with the originals, right?

edit: eh, guess I should have read the rest of the posts. :) Never mind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.