There is such a code

<?php include('config.php'); $today = date ("d"); $sql1=mysql_query("SELECT fio, doljnost, podr, bdate FROM dnuhi WHERE bdate LIKE '".$today."%' "); while($rows=mysql_fetch_array($sql1)) { $fio=$rows['fio']; $doljnost=$rows['doljnost']; $podr=$rows['podr']; echo $fio." - ".$podr." - ".$doljnost; echo "<br>"; } $to = 'qqq@qqq.ru'; $subject = 'Дни рождения!'; $message = ' <html> <body> <p>Дни рождения</p> <table> Вот сюда нужно вывести результаты в виде: Иванов Иван Иванович - Астрахань - Кадровик Петров Петр Николаевич - Владивосток - Менеджер </table> </body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= 'From: mail@qqq.ru <mail@qqq.ru>' . "\r\n"; mail($to, $subject, $message, $headers); ?> 

I can not figure out how to insert from the result of the request into the body of the letter. So that all this is gone in one letter.

    1 answer 1

    Collect the rows for the table immediately in a loop:

    ...

     $message_rows = ""; while($rows=mysql_fetch_array($sql1)) { $message_rows .= "<tr><td>".$rows['fio']."-".$rows['podr']."-".$rows['doljnost']."</td></tr>"; } 

    Next, specify the string variable in $ message

      $message = ' <html> <body> <p>Дни рождения</p> <table> '.$message_rows.' </table> </body> </html> ';