0

I have a preview page or an email that is created with html and php. So basically on this page there is a big $body string that can contain any html and php. But I want to send this string to another page with a link:

echo '<a href="[theURL]?body='.htmlentities($body).'">Click here</a>';

the link goes to a second php page that should display everything the same was as on the first page:

<?php
    if(isset($_GET["body"])){
        echo html_entity_decode($_GET["body"]);
        //echo htmlspecialchars_decode($_GET["body"]);
    }
?>

the second page gets the string in the url, but remain empty. so either it's not decoding it right or i missed something simple? the url looks something like this: %20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20

Is there a better way to do this than $_GET? I tried to use a form instead of a link and use post, but it didn't seem to work.

ioan
  • 295
  • 2
  • 7
  • 23
  • 2
    `urlencode()` is what you should actually be using. urls have length limits, so if body is large you should not use this apporach –  Jan 08 '18 at 01:40
  • yup i got a Request-URI Too Long error for some emails. gonna need to send the body string with something other than $_GET, and $_POST didn't seem to work :S – ioan Jan 08 '18 at 02:35
  • I tried to create a form inside the email that puts the body in a hidden input and a submit button instead of the link, but clicking it does nothing: $body .= '
    ';
    – ioan Jan 08 '18 at 02:46
  • 1
    you cant put a form in an email and im not sure ehy you are trying to –  Jan 08 '18 at 03:30
  • i was trying to send the body string through $_POST instead of GET, to avoid the url awkwardness. Is there another way to use POST from an email? – ioan Jan 08 '18 at 20:11
  • 1
    i think we may be using `email` in a different context. if you are just trying to send a string from one page to another, and its to large for the url, post is a good option; otherwise you need to store it locally in a db or a file at least temporarily –  Jan 08 '18 at 20:37
  • ok i guess ill be saving them all in the database, thanks :) – ioan Jan 09 '18 at 01:36

0 Answers0