dongxia5394 2016-06-02 21: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-02 21: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部