Answer the question
In order to leave comments, you need to log in
How to form the body of a letter or how to substitute variables into an already formed letter?
Hello! I have a self-written project in which I connected phpmailer, I have a task when registering a new user to the mail, to poison his registration data. Now my body of the letter is formed in a variable and the data is substituted (see screenshots)
I would like to make the letter in a separate file and I would take it with a function, for example file_get_contents and there were already substituted values, well, something like this, and not like now the entire letter is in a variable.
1 screen
screen 2
Answer the question
In order to leave comments, you need to log in
And what's the problem?
If there is no template engine, then ob_get_contents
help.
php.net/manual/ru/function.ob-get-contents.php
Primitive example:
<table>
<tr>
<td><?= $variable_1 ?></td>
</tr>
<tr>
<td><?= $variable_2 ?></td>
</tr>
</table>
$mail = new PHPMailer();
$variable_1 = "Привет";
$variable_2 = "Чухча";
ob_start();
require_once("template.php");
$body = ob_get_contents();
ob_end_clean();
.....
$mail->Body = $body;
.....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question