List multiple MYSQL records in PHP email to send them all at once

Asked

Viewed 185 times

-2

I have a real estate system that lists several MYSQL records. I have this code below so that these various records are sent in a single email, but it only sends a record.

Look at the code:

<?php require_once('conexao.php'); ?>
<?php
$sqlxml = "select conta.dominio,conta.id,conta.modelo,imoveis.id,imoveis.cod,imoveis.titulo,imoveis.vvenda,imoveis.vtemporada,imoveis.vanual,imoveis.tipo,fotos.cod,fotos.foto,imoveis.descricao,imoveis.cidade, imoveis.data, imoveis.endereco, conta.nome, imoveis.dormitorio, imoveis.banheiro, imoveis.atotal, imoveis.areatotalmedida, imoveis.bairro from conta inner join imoveis on conta.id = imoveis.cod inner join fotos on fotos.cod=imoveis.id where imoveis.status='2' AND imoveis.vvenda < '500000' GROUP BY imoveis.id";
$rsqlxml = mysql_query($sqlxml)
or die ("Banco XML não abre!");

$quebra_linha = "\n";
$emailsender = "[email protected]";
$emailorigem = "[email protected]";
$assunto = "Roteiro do Imóvel - Sugestão de imóveis";

while($rowxml = mysql_fetch_array($rsqlxml))
{
    $mensagemHTML = "
    <strong>Id:</strong> ".$rowxml[3]. "<br>
    <strong>Título:</strong> ".$rowxml[5]. "<br>
    <strong>Categoria:</strong> ".$imvtipo. "<br>
    <strong>Imóvel para:</strong> ".$tipodoimovel. "<br>
    <strong>Valor:</strong> ".number_format($rowxml[6], 2, ',', ' '). "<br>
    <strong>Cidade:</strong> ".$imvcidade. "<br>
    <strong>Bairro:</strong> ".$mostrarbairroemail. "<br>
    <img src='http://www.roteirodoimovel.com.br/cp/clientes/".$rowxml[4]."/".$rowxml[3]."/".$rowxml[11]."' width='170' height='127'><br>
    <strong>Descrição:</strong> ".$rowxml[12]. "<br>
    <strong>Visualizar:</strong> ".$rowxml['0']."/".$rowxml['2']."/detalhes.php?idimovel=".$rowxml['3']."<br>
    "; 
 }

$headers = "MIME-Version: 1.1".$quebra_linha;
$headers .= "Content-type: text/html; charset=utf-8".$quebra_linha;
$headers .= "From: ".$emailorigem.$quebra_linha;
$headers .= "Return-Path: " . $emailorigem . $quebra_linha;
$headers .= "Reply-To: ".$emailsender.$quebra_linha;
$mailsend=mail($emailsender, $assunto, $mensagemHTML, $headers, "-r". $emailsender); 
?>

What was done wrong?

1 answer

0

It is only sent the last record because every turn in the while $mensagemHTML has its value rewritten.

To solve this set the variable before while and concatenate the string with .=

change:

$mensagemHTML = "longo html";

To:

$mensagemHTML = "";
while(...){
    $mensagemHTML .= "longo html";

Browser other questions tagged

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