Jump to content

Php in an iframe acting funny.


segwaypirate

Recommended Posts

Here is the code in question:

<form method="post" action="../php/sendmail.php">
   <?php
   function RandomLine()
   {
   $textfile = "../messages/compliments.txt";
      if(file_exists($textfile))
      {
      $compliments = file($textfile);
      $string = $compliments[array_rand($compliments)];
      }
      else
      {
      $string = "Error";
      }
      return $string;
   }
   $line = RandomLine();
   echo "<p style='color: red;'>"."$line"."</p>";
   ?>
<br>
<input type="hidden" name="email" value="[email protected]">
<input type="hidden" name="subject" value="random compliment generator">
<input type="hidden" name="message" value="$line">
<input type="hidden" name="to" value="[email protected]">
<input  type="submit" name="sendtext" value="Send to phone!">
</form>

 

And here is the php from sendmail.php:

<?php
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$to = $_REQUEST['to'];

$sent=mail($to, $subject, $message, "From: $email");
if($sent)echo "<br><p>The message was sent!</p>";
else echo "<br><p>There was an error while sending the message.</p>";
?>

 

When the form from the first bit of code is opened in an iframe, the echo displays the correct code but if the button is sent, the sms/email received simply says "$line".  Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/212413-php-in-an-iframe-acting-funny/
Share on other sites

This line <input type="hidden" name="message" value="$line"> explicitly gives the literal value '$line' to the $_REQUEST['message'] element. Change it to

<input type="hidden" name="message" value="<?php echo $line; ?>">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.