1

Topic: How in php to use a template for the letter?

All greetings!
I want to send letters that the letter template was formed with html a file, googled on a miscellaneous: send php html template and  , but all results - template formation directly in the code.
In  here is how it is convenient:

string body, Title;
using (var sr = new System. IO.StreamReader (Server. MapPath ("\\App_Data \\EmailTemplates \\") + "CabinetGreated.html"))
{
body = sr. ReadToEnd ();
}
string messageBody = string. Format (body, "Organizer", email, password, Id, Title);

CabinetGreated.html - [url =] joxi.ru/KAgMW4I4XEP4ml [/url]
How it is possible to make same in php?

2

Re: How in php to use a template for the letter?

You are assured, what it php?

3

Re: How in php to use a template for the letter?

Hett wrote:

you are assured, what it php?

No, I specified that "In  here is how conveniently:".....
Also asked as such task to solve in php

4

Re: How in php to use a template for the letter?

Yes, something I did not sleep today smile
So and in what a problem, here only two moments:
1. File reading in a variable http://php.net/manual/ru/function.file-get-contents.php
2. printf http://php.net/manual/ru/function.sprintf.php

5

Re: How in php to use a template for the letter?

Hett wrote:

Yes, something I did not sleep today smile
So and in what a problem, here only two moments:
1. File reading in a variable http://php.net/manual/ru/function.file-get-contents.php
2. printf http://php.net/manual/ru/function.sprintf.php

Thanks, are similar it:

<? php
$num = 5;
$location = ' a tree ';
$format = ' %d monkeys sit on %s';
echo sprintf ($format, $num, $location);
?>

6

Re: How in php to use a template for the letter?

Hett wrote:

Yes, something I did not sleep today smile
So and in what a problem, here only two moments:
1. File reading in a variable http://php.net/manual/ru/function.file-get-contents.php
2. printf http://php.net/manual/ru/function.sprintf.php

Hett wrote:

Yes, something I did not sleep today smile
So and in what a problem, here only two moments:
2. printf http://php.net/manual/ru/function.sprintf.php

Similar not , as a letter template:

.....
<table width = "100 %" cellpadding = "0" cellspacing = "0" style = "min-width:100 %;">
<tr>
<td width = "100 %" style = "min-width:100%;background-color:#58585A;color:#FFFFFF;padding:30px;">
<p style = "font-size:16px;line-height:20px;font-family:Georgia,Arial,sans-serif;text-align:center;"> 2017 COPYRIGHT - EDMDESIGNER </p>
</td>
.....

There characters of % are, therefore an error - Warning: sprintf (): Too few arguments in
Prompted :

foreach ($args as $key => $value) {
if (! is_array ($value) &&! is_object ($value)) {
$search = ' {$ '. $key. '} ';
$content = str_replace ($search, $value, $content);
}
}

7

Re: How in php to use a template for the letter?

What for any  when PHP itself is able to substitute values of variables....

<? php
$num = 5;
$location = ' a tree ';
$result = <<<TPL
{$num} monkeys sit on {$location}
TPL;
echo $result;

8

Re: How in php to use a template for the letter?

vkle wrote:

What for any  when PHP itself is able to substitute values of variables....

<? php
$num = 5;
$location = ' a tree ';
$result = <<<TPL
{$num} monkeys sit on {$location}
TPL;
echo $result;

Thanks, and you could not write taking into account that in my variable  html a letter template:

<? php
$num = 5;
$location = ' a tree ';
$EmlTemplate = file_get_contents (' /wp-content/plugins/registration_wpforms/EmlTemplate ');
$result =????
echo $result;

9

Re: How in php to use a template for the letter?

Sputnick;
If a template in a variable - then eval () to use.
But, judging by the code, the template lives in a file. Then it is enough  this file.
Certainly, both the assignment statement should contain in that and in other case a template file.

10

Re: How in php to use a template for the letter?

vkle wrote:

Sputnick;
If a template in a variable - then eval () to use.
But, judging by the code, the template lives in a file. Then it is enough  this file.
Certainly, both the assignment statement should contain in that and in other case a template file.

Yes, a template in a file as to edit a template in a file with  the code inconveniently.
Instead of could throw an example ( this file. / the assignment statement) should contain a template file
I that with  never dealt

11

Re: How in php to use a template for the letter?

vkle wrote:

Sputnick;
If a template in a variable - then eval () to use.
But, judging by the code, the template lives in a file. Then it is enough  this file.
Certainly, both the assignment statement should contain in that and in other case a template file.

In that case it will be necessary that each variable has been concluded in <? php?> (<? =?>)

$a = ' para bellum ';
$data = require (' template.html ');

template.html

Si vis pacem, <? = $a?>

12

Re: How in php to use a template for the letter?

As a variant, it is possible to take smarty, twig, jinja, etc. the ready decision for

13

Re: How in php to use a template for the letter?

Sputnick wrote:

to edit a template in a file with  the code inconveniently

Why it is inconvenient, if not a secret, the text editor without combined php+html illuminations of the code or is more powerful to reason volume?
Here to dump templates and the code in one heap it is not necessary. However, "on a knee" that only do.

Sputnick wrote:

and you could not

Could. Catch a broad gull from the console.

$ cat./test.php
<? php
$num = 5;
$location = ' a tree ';
require ' template.tpl ';
echo $result;
$ cat./template.tpl
<? php $result = <<<TPL
<div>
{$num} monkeys <i> sit </i> on <b> {$location} </b>
</div> \n
TPL;
$ php-f./test.php
<div>
5 monkeys <i> sit </i> on <b> a tree </b>
</div>

However, if really  to edit a compound php+html (in such variant a template  ) then look that is more convenient for a specific case,  or file reading + eval ().

Hett wrote:

In that case it will be necessary that each variable has been concluded in <? php?> (<? =?>)

Yes well it is possible, if very much it would be desirable... And what for?

14

Re: How in php to use a template for the letter?

That it was possible to process variables, for example htmlspecialchars, etc.
In a case with a wrapped up template in possibility single line will be less.

15

Re: How in php to use a template for the letter?

Hett wrote:

That it was possible to process variables, for example htmlspecialchars, etc.
In a case with a wrapped up template in possibility single line will be less.

Tady towards high-grade  with various modifiers. However, that in a unique template to substitute the ten variables, do not see sense to make a fuss. To prepare in variables a content for the publication easier.
Other question.
Judging by "/wp-content /", at author Vordpress it is used.
Whether is not present in him  with possibility to return a content as a line? And that, maybe, in vain here in the invention  we are engaged.