dongxia5394 2016-06-03 05:39
浏览 36
已采纳

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

  • 写回答

3条回答 默认 最新

  • dqf60304 2016-06-03 05:49
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line