PHP在电子邮件中发送数组记录

Hi can someone help me about sending a email with the array data I gathered? I'm trying to fetch records on the DB using array and then I'll email it

Here's my code: I will get the records I want first:

$queclient_credit = "SELECT company, credits FROM clients WHERE credits <= 20 and company !='' ORDER BY credits ASC ";
    $getque = mssql_query($queclient_credit) or die();
    while ($rowclient_credit=arrayfetch($getque)){
            $rowcompany = $rowclient_credit['company'];
            $rowcredits = $rowclient_credit['credits'];
Then put it on array:
        $data = array(
                'company'=>$rowcompany,
                'credits'=>$rowcredits
        );


   $dat = implode(' : ', $data);
    }
        if($rowcredits<= 20){
        $from='email@gmail.com';
        $to = 'email@gmail.com';


    $gmailPass = 'password';
    require('phpmailer/5.1/class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();

    $mail->SMTPAuth = true;

    $mail->SMTPSecure = "ssl";

    $mail->Host = 'smtp.gmail.com';

    $mail->Port = '465';

    $mail->Username = $from;

    $mail->Password = $gmailPass;
    $mail->From = $from;
    $mail->FromName = $from;
    $mail->AddReplyTo($from, $from);
    $mail->Subject = 'Credit System ';
    $mail->Body = $message;
    $mail->MsgHTML('<b><p>'.$dat.' credits<p><b>');
    $mail->IsHTML(true);
    $mail->AddAddress($to, $to);
if(!$mail->Send()){
     // $mail->ErrorInfo;
}else{
    echo 'Message Successfully Sent!';
    $mail->ClearAddresses();
    $mail->ClearAttachments();
    }
}

Thank you for who will answer

If you want display all the details through table in mail use like this,

  $data="<table><tr>
                <th></th>
                <th></th>
                </tr>";

  while ($rowclient_credit=arrayfetch($getque)){
            $rowcompany = $rowclient_credit['company'];
            $rowcredits = $rowclient_credit['credits'];
            $data.="<tr> <td>".$rowcompany."</td>
                         <td>".$rowcredits."</td>
                    </tr>";
    }

  $data.="</table>";


    $mail->MsgHTML($data);

You have to create a variable (you already have it anyway: $message), and fill it with your array data by using foreach function to concatenate string. For example:

$message = "";
foreach($getque as $g)
{
       $message .= "</br>".$g["table_column_name"];
}
...

I am not a pro but i can give you suggestion. Every thing in your code is ok but Yes, your code will send only one record, Just make two changes, your code will start sending all the records if array.

$data = array(
            'company'=>$rowcompany,
            'credits'=>$rowcredits
    );

to

$data[] = array(
            'company'=>$rowcompany,
            'credits'=>$rowcredits
    );

2nd change is move $dat = implode(' : ', $data); out of your while loop.

you can format your result using different html tags as per your requirement if you want some styling in your email.

hope this will help.