Substitute a variable within a field in a table

0

My problem is this:

I have a table with several fields, in one of them type longtext , the user saves a mail sending format, for example

Hello $nombre I send this test mail to $ name

so far so good, the program in php works perfectly and sends the mail, the problem appears when wanting to replace the variable $ name, by the name of the recipient, it does not do it, but it sends me the mail as appears in the example and I want to replace me $nombre.

They could help me.

This is the code

<?php
include_once('../include/class.phpmailer.php');

$mail             = new PHPMailer();

$body = "
<!DOCTYPE html>
<html lang='es'>
<head>
    <meta charset='UTF-8'>
    <title>Title</title>
</head>
<body>
    $cuerpo_correo
</body>
</html>";

//$body             = eregi_replace("[\]",'',$body);

$mail->IsSendmail(); // telling the class to use SendMail transport

$mail->From       = "[email protected]";
$mail->FromName   = "Gcnet";

$mail->Subject    = $asunto_correo;

$mail->AltBody    = "Si no puedes ver este mensaje, por favor utiliza un programa de correo compatible HTML."; // optional, comment out and test

//$mail->MsgHTML($body);
$mail->MsgHTML(utf8_decode($body));


$mail->AddAddress($email1, "Gcnet");



if(!$mail->Send()) {
//  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
//  echo "Message sent!";
}
?>
<!DOCTYPE html>
<html lang="es" >
<head>
  <title>Gcnet</title>
  <meta charset="utf-8" />
</head>

<body>
</body>
</html>

The mail body variable replaces it well. I also give you an example of what is in the variable $ body_message that in turn is collected from the BD.

This email is sent to $ name because you are registered in our newsletter.

This would be the variable $ email_subject, the problem is that it does not replace the other variable $ name, which is inside $asunto_correo

I hope you have explained me well

Hello, this is the code that makes the call: if (isset ($ _ POST ['send_mail'])) {

$tipo_plantilla = $_POST['tipo_plantilla'];
$asunto_correo = $_POST['asunto_correo'];
$cuerpo_correo = $_POST['p_plantilla'];
$enviado = $_POST['enviado'];
$codigo_cupon = $_POST['codigo_cupon'];
$fecha_inicio = $_POST['fecha_inicio'];
$fecha_final = $_POST['fecha_final'];
$descuento = $_POST['descuento'];

$hoy = date("Y-m-d");
$ip1 = getenv("REMOTE_ADDR");

if($codigo_cupon != "")
{
    $result_clientes_tmp = mysql_query("Select * From clientes_tmp ",$con);

    while($row_clientes_tmp=mysql_fetch_array($result_clientes_tmp)) {

        $codigo_cliente = $row_clientes_tmp['cod_cli'];
        $email1 = $row_clientes_tmp['email'];

        //se inserta el cupón
        $result1 = mysql_query("Insert into cupones(cupon, dto, id_cli, fecha, fecha_envio, fecha_vto) 

values ('$ code_cupon', '$ discount', '$ customer_code', '$ start_date', '$ today', '$ end_date') ");

    }
}


if($enviado == 1)
{
    $p_enviado = 1;
}else
{
    $p_enviado = 0;
}


$result1 = mysql_query("Insert into correos(id_plantilla, asunto_correo, cuerpo_correo, enviado, hash, ip, fecha, id_cli) 

values ('$ template_type', '$ mail_subject', '$ mail_body', '$ p_enviated', '$ string', '$ ip1', '$ today', '$ cli_id') ");

//se averigua el id del correo
$result_correos = mysql_query("Select * From correos WHERE hash='$cadena'",$con);

if(mysql_num_rows($result_correos)>0)
{
    $row_correos = mysql_fetch_array($result_correos);

    $id_correo = $row_correos['id'];

}

//se insertan los clientes a los que se les va a enviar el correo
$result_insert = mysql_query("Select * From clientes_tmp ",$con);

while($row_insert=mysql_fetch_array($result_insert)) {

    $nombre = $row_insert['nombre'];
    $email1 = $row_insert['email'];

    $result1 = mysql_query("Insert into correos_clientes(id_correo, nombre, email, ip, id_cli) 

values ('$ email_id', '$ name', '$ email1', '$ ip1', '$ id_cli') ");

    if($p_enviado == 1)
    {
        include("sendcorreos.php");
    }
}

I pick up the variables, through POST and then through an include I make the call to the function that sends the mail. The mail sends it well, without any problem. What happens to me is that this variable in turn has a variable, which is collected from the DB and the one I want to replace. To understand me, it is a BD field, which the user personalizes and what I want is for him to send that field (this is fine), but in turn, personalize it for each user. In the BD, there are for example the following: Hello $ name, we welcome you, what I want is that the variable name be changed by the name of the person, and the variable $ cuerpo_correo, also I pick it up from the BD, not is fixed, so I can not use the echo "Hello $ name" ;, in turn the variable I pick it from the DB, that is, what I want is that within the variable I replace another variable, it is to make a personalized welcome mail system. I hope you have explained to me.

    
asked by Alfonso 16.09.2018 в 19:45
source

0 answers