Jump to content

Recommended Posts

Hello,

 

I am creating a mass mail system for my company. I want to have templates available for different types of mail. I am wondering how to set it up so that what the sender types in the textarea gets placed in the template file properly.

 

I did this as a test

 

$testvar = 'Inserted Test Var';
$template = file_get_contents(TEMPLATE_DIR.'template1.php'); // I have $testvar inside this template file

echo $template;

 

I get nothing or I get $testvar depending if I have the php tags below

 

Here is template1.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?=$testvar ?> <!-- This gives me nothing-->
$testvar <!-- this gives me $testvar -->
</body>
</html>

 

How can I make it so I can take the $_POST data from a form, and set the template code into a var having it replace a var inside the template file with the data from the form

 

I hope that makes sense to ya's.

 

 

Nate

 

 

Link to comment
https://forums.phpfreaks.com/topic/87061-solved-probably-a-simple-task/
Share on other sites

Solved it... I found the script I used before to do this type of thing

 

<?php

$testvar = 'Inserted Test Var';
include(TEMPLATE_DIR.'shipping_pizza.php');
echo $body;
?>

 

Here is where it all happens at.

 

<?php ob_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?=$testvar ?> <!-- Gotta have it in PHP tags. ?>
</body>
</html>
<?php
$body = ob_get_contents(); /* this is where it happens... this takes the contents of ob_start and puts it inside a var. */
ob_end_clean(); /* clears the buffer without displaying it */
?>

<?= is a <? shortag.

 

Disable short tags and watch it stop working.

 

I don't use short tags....

 

e.g <? vs <?php

 

 

I used the shorthand echo statement <?=$var ?>

 

I do believe there is a difference between the 2.

 

One is laziness :) and the other is a build in shorthand statement.

 

Nate

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.