Using PHP variables with file_get_contents

微信扫一扫,分享到朋友圈

Using PHP variables with file_get_contents

I have a newsletter template in one file and a mail script in another file which basically pulls email addresses from a database and loops through each one sending the email to them.

I am using this code to get the contents of the newsletter template:

$content = file_get_contents('attach/T_newsletter.php');

What I need to do now is send PHP variables along with this eg:

T_newsletter.php?test=hello

and then be able to pull them from the URL in the template and adjust the content accordingly.

Could someone explain how I would do this please?

Thanks for any help

If you want to do that, you will need to call that file “T_newsletter.php” as part of a URL:

$content = file_get_contents("http://yourdomain.com/T_newsletter.php?test=hello");

and inside T_newsletter.php:


The other option would be to use a template engine like Twig
or Smarty
to parse the files directly if you do not wish to make an HTTP request.

微信扫一扫,分享到朋友圈

Using PHP variables with file_get_contents

韩国交易所MineBit与JLAB达成战略合作

上一篇

腾讯架构大调整:消失的 3 个事业群和致敬阿里

下一篇

你也可能喜欢

Using PHP variables with file_get_contents

长按储存图像,分享给朋友