I must send mails to different users with different messages depending on specific parameters. Currently I have the text to send, parameterized in hard, that is, in this way as an example:
$nombre = $usuario->__GET('Nombre');
$email = $usuario->__GET('Email');
$informacion= $reportes->__GET('Reporte');
$texto = "Estimado ".$nombre.", este correo es para informarle qué ".$informacion.";
enviar_mail($nombre ,$email, $texto );
What I want is that the text is not written in the code but in the database with the same parameters (since there are many different ones and they vary over time) to be able to have this type of script:
$nombre = $usuario->__GET('Nombre');
$email = $usuario->__GET('Email ');
$informacion = $reportes->__GET('Reporte');
$texto = $reportes->__GET('Texto');
enviar_mail($nombre ,$email, $texto );
But the text that appears in the parameter $texto
appears with the parameters as a string.
"Estimado ".$nombre.", este correo es para informarle qué ".$informacion.";
I have tried to store it in the database in the following ways:
- "Dear ".$name.", This email is to let you know what ".$information."
- Dear ".$name.", this email is to inform you what ".$information.
- Dear $name, this email is to inform you what $information
I don't know if it's not possible or I'm very lost on how to do this.
Cheers
Create a structure for your parameters and store them in the database, for example, let's say you use the following structure to identify the parameter name
|param:nombre|
, then you store in the database a text like this:'Hola |param:nombre|, ¿te acuerdas de mi?'
.When you retrieve the text from the database, you replace the structure with the corresponding value, as you are using PHP so you do it with the str_replace() function .
You make a function like this:
then you call it like this:
More information
The function you need to achieve that is
eval
, I'll give you an example: