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

报告相同问题?

悬赏问题

  • ¥20 mpich安装完成后出问题
  • ¥15 multisim仿真
  • ¥15 stm32循迹小车代码问题
  • ¥15 输入一堆单词,使其去重输出
  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移
  • ¥15 如何用python处理excel的数据(极值标准化)
  • ¥15 三向应力状态求剪应力
  • ¥15 jupyter notebook如何添加libGL.so.1库
  • ¥20 easyPoi能否实现下拉多选或者复选框