While inside mail function

0

I have the following question: I want to cause the results of a While (basically 10 records) to be inserted into the mail function. I do not have the slightest idea how I'll do it, someone can help me.

I want each result to be displayed exactly where "Here comes the result 1 of While" and so on ...

Below the code most exemplified for the stack's friends can help me:

<?php
mysql_select_db($database_microf, $microf);
$query_sa1 = "SELECT * FROM sa1 WHERE  mesvenc='$mes' AND situacao='Pendente'  ";
$sa1 = mysql_query($query_sa1, $microf) or die(mysql_error());
$row_sa1 = mysql_fetch_assoc($sa1);
$totalRows_sa1 = mysql_num_rows($sa1);


mysql_select_db($database_microf, $microf);
$query_sa12 = "SELECT SUM(valor) FROM sa1 WHERE  mesvenc='$mes' AND situacao='Pendente'  ";
$sa12 = mysql_query($query_sa12, $microf) or die(mysql_error());
$row_sa12 = mysql_fetch_assoc($sa12);
$totalRows_sa12 = mysql_num_rows($sa12);

$total=$totalRows_sa1;
$valor=number_format($row_sa12['SUM(valor)'],2,',','.');


if($totalRows_sa1>0){

//hader para o e-mail ir com codificações corretas e tudo mais.
$headers .= "Content-Type:text/html; charset=UTF-8\n";
$headers .= "MIME-Version: 1.0\n";
//
$destino = '[email protected]';
$nome="Sistema Financeiro";
$email="[email protected]";

//Envia mensagem para o administrador do site
$resposta = mail("$destino","Relatorio de Contas Pendentes",
"<p><b>Atenção!</b></p>

-------------------------------------------------</br>

Existem <b>$total</b> contas  do mês de <b>$mes</b> que ainda não foram pagas.</br>
Elas Totalizam <b>R$ $valor</b> </br>

As contas a serem pagas são:
Aqui vem o resultado 1 do While</br>
Aqui vem o resultado 2 do while</br>
Aqui vem o resultado 3 do while</br>




Verifique por favor...</br>
<a href='http://meudominio.com'><img src='http://meudominio.com/cron/images/BtnAcessarSistema.png' /></a></br>

--------------------------------------------------</br>
<p>Essa é uma mensagem enviada através do seu sistema. Não Responda.</p>
","$headers"."From:$nome<$email>");




?>
    
asked by anonymous 08.05.2016 / 17:17

1 answer

0

There are several ways for you to do this, one of them would be to assign any variable to the type text and to rewrite the text inside the loop with whatever you want, I would do something like this:

<?php
$relatorio = '';
$query = pdo->query($meuSql);
foreach(row as query)
{
    $relatorio .= "coluna1 : ".row['colunatabela']."/n".
                  "coluna2 : ".row['colunatabela2'];
    // ...
}

$headers .= "Content-Type:text/html; charset=UTF-8\n";
$headers .= "MIME-Version: 1.0\n";
$mensagem = "Relatorio mensal das suas contas pendentes. \n\n\n".
            "--------------------------------------------------\n".
            $relatorio.
            "--------------------------------------------------\n".
            "seu rodapé do email.bla bla bla\n";
$destino = '[email protected]';
$nome="Sistema Financeiro";
$email="[email protected]";
$subject = $nome." - Relaório mensal de contas...bla.bla.bla\n";
mail($destino, $subject, $mensagem, $headers);
?>

If you want to add text to variables in php, you have to use "text". and if you want a loop inside the other you make another "foreach (...)" or while (...) within the first loop, in my case the line: foreach (row as query) , so it is up to you.

That's just the beginning, at the very least, put the neurons to burn, the "savings" to sneak and finger-melt the code, ririri

health and peace!

    
08.05.2016 / 18:07