Reputation: 1210
I want to send emails and store all email layouts in a seperate subfolder.
Let's assume the file emails/mailLayout.php
contains something like
<a><?php echo $item["name"]?></a>
Approach to get the content:
$item["name"] = "John Doe";
$emailContent = file_get_contents("emails/mailLayout.php);
//send mail...
$emailContent
should contain <a>John Doe</a>
but thats not the case
Any solutions or better approaches?
Upvotes: 1
Views: 83
Reputation: 1267
For this just do one thing :
For this first get the content from the .php file and then do something like this :
$name = "John Doe";
$text = file_get_contents("emails/mailLayout.php");
$text = str_replace('USERNAME', $name, $message);
and in your mailLayout.php just replace the php value with some Constants.
for ex : Hi this is USERNAME
or any unique value.
Hope it helps!!!
Upvotes: 0
Reputation: 1497
You can use php's output buffer :
$item["name"] = "John Doe";
ob_start();
require "emails/mailLayout.php";
$emailContent = ob_get_contents();
ob_end_clean();
//send mail...
file_get_contents
does not interpret PHP code
Upvotes: 2