John Michael Ayeras Rivera John Michael Ayeras Rivera - 6 months ago 11
PHP Question

PHP Sending array records in email

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

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);