Problem in using str_replace

Asked

Viewed 50 times

-2

I’m picking up the field:

$body = $result['mensagem_email'];

and emailing by $mail.

The problem is that I need to insert parameters in the html code I search in the database record and before sending the html code to [nome] and [email] with str_replace.

It’s working except for the fact that the email goes with the body of the duplicate message. Below the complete code: (the GAVE RIGHT PO**) did not work...

<?php
while($result = mysql_fetch_array($query)) {
  $teste = "DEU CERTO PO***";
  $id = $result[0];
   $to = $result[1];
   $status = $result[10];
    $pixelLead = $result['id_lead'];// variavel que vai no link do pixel
    $pixelCampanha = $result['id_campanha'];// variavel que vai no link do pixel
    $subject = $result['assunto_email'];
    //$body = str_replace('[teste]', $teste, $body );
    $body = $result['mensagem_email'];
    $body .= "<img src='http://www.tnnt.me/pixel.php?idLead=".$pixelLead."&idCampanha=".$pixelCampanha."' />";
    $body .= str_replace('[teste]', $teste, $body );

// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: $nome_remetente <$email_remetente>\r\n";
$headers .= "Return-path: $nome_remetente <$email_remetente>";
mail($to,$subject,$body,$headers, "-r". $email_remetente);
$datahora=date('Y-m-d h:i:s'); //seta a data hora
mysql_query("UPDATE $tabela1 SET status_lead = 1 WHERE id_lead = $id");
mysql_query("INSERT INTO campanha_resultado (id_campanha, id_lead, data_envio)  VALUES ($pixelCampanha,$pixelLead,NOW()) ");
printf("<font face=’tahoma’>$id ) mensagem para <b>$to</b> <font color=’#ff0000’><b>enviada com sucesso!</b></font></font>");

}
?>
  • 4

    $body .= str_replace(... there’s the mistake.

1 answer

2

You’re concatenating the output of str_replace which is the content with $body altered with its own $body.

You must do $body = str_replace('[teste]', $teste, $body );

  • I believe that’s right

Browser other questions tagged

You are not signed in. Login or sign up in order to post.