Hi,

I have a form which has an auto-response email and works beautifully. Now, I want to replace the html content of the body with a php variable. The variable gets its value from a database and the content is entered via browser wysiwyg editor.
If I pass the variable as a hidden field like this:

<?php echo $row_email_body['email1_body']; ?>

.. the html prints onto the page the form is on as well as on the email

If I try to use it from an unfiltered recordset the content doesn't show on the email.

$top = "<br>";
  $body = print($row_email_body['email1_body']);
  $bottom = "<br>";
  $from = "Competition";
  // set parameters
  $recipient = $HTTP_POST_VARS["email"];
  $subject = "Competition";
  $message = $top . $body . $bottom;

Does anyone know what I may be doing wrong here?

Thanks for any help.

    Presumably, your $row_email_body['email1_body'] is being set on the previous page? Hard to tell, since you only posted a snippet of the code, and you reference passing the variable in a hidden field.

    That being the case, you need to define your $body variable from the POST array like below:

    $top = "<br>"; 
    // Change the Array key name to wahtever the hidden element's name is
      $body = $_POST['row_email_body']; 
      $bottom = "<br>"; 
      $from = "Competition"; 
      // set parameters 
      $recipient = $HTTP_POST_VARS["email"]; 
      $subject = "Competition"; 
      $message = $top . $body . $bottom;
    

    In other words, if your hidden field looks something like this:

    <input type="hidden" name="[b]email_content[/b]" value="<?php echo $row_email_body['email1_body']; ?>">
    

    Then your $body variable would look something like this (Note the part in bold above):

    $body = $_POST['email_content'];
    

    Sorry to change the name around, hope I don't confuse you, but I figured if I changed the name, it would make more sense so you'd know what to associate with what.

    If I am off base with my thoughts, then let me know, and post more code, so we can better decipher how you are defining your variables.

      Thanks Defender,

      I tried this and it didn't work - well, it does send the html content correctly as an email but the so-called hidden field was not hidden, but displayed a portion of the html content on the form page. I think is was doing this because the html was developed dynamically from a php browser wysiwyg/html editor.

      Happily, I've found a way around the problem from another thread on this forum -

       $body = file_get_contents("http://mysite.com/email1_display.php"); 

      Where the file /email1_display.php is the displayed result of the form which uses the editor mentioned above.

      It works really well!

      🙂

        Yeah, I actually just read the other post... Your descriptions of your issues didn't appear to be the same, but either way, if you got it figured out, great. Be sure to mark them both resolved...

          Write a Reply...