-1

I'm trying to send a webpage as an email. The content of this webpage is based on variables, which are called using the _GET method.

I have this part of code, which works if I don't put any variables in the url, but echoes [function.file-get-contents]: failed to open stream: No such file or directory in... as soon I write ?variable= behind the URL.

<?

$var_one = $_GET['var_one'];
$var_two = $_GET['var_two'];
$from = "Company name";
$from_email = "company@mail.com";
$email_text = file_get_contents("mail_this_page.php?varone=".$var_one."&vartwo=".$var_two);

$headers = "From:abc@mail.com";
$headers = "From: $from <$from_email>\r\n". 
           "MIME-Version: 1.0" . "\r\n" . 
           "Content-type: text/html; charset=UTF-8" . "\r\n";

mail('guest@mail.com', 'Hello', $email_text, $headers);

?>

So, the problem is in the file_get_contents line.

$email_text = file_get_contents("mail_this_page.php");

works, but

$email_text = file_get_contents("mail_this_page.php?varone=".$var_one."&vartwo=".$var_two);

doesn't. What am I doing wrong? How can I pass the variables using this method?

Jeffrey van Zwam
  • 105
  • 1
  • 15

1 Answers1

0

The function file_get_contents() takes a string of the file name as a parameter. This is then used to check with the filesystem for a file with that exact name. As the filename you are passing doesn't end at the extension '.php', it's looking for a file with the name which includes everything after (and including) the '?'.

It is literally looking for the file mail_this_page.php?varone=VAR_ONE&vartwo=VAR_TWO (assuming the variables evaluate as such) on the hard drive.

gabe3886
  • 4,235
  • 3
  • 27
  • 31