简体   繁体   English

PHP Mail()使用表从数据库发送数据

[英]Php mail() send data from db with table

i want to send mail with data from database and using php mail() this is my code : 我想使用数据库中的数据发送带有数据的邮件,并使用php mail()这是我的代码:

<?php
class emailKoala{
  public function __construct()
  {
  }
public function kirimEmailDaftar($email,$name,$order_id,$order_hargatotal){
    include "../config.php";
    $sqlbank="SELECT * FROM `bank`";
    $querybank=mysql_query($sqlbank);

    $to      = "$email";
    $subject = "order information!";
    $message = 'thanks :) this is bank account
<table>
  <tr>
    <th>Bank</th>
    <th>Number</th>
    <th>Other</th>
  </tr>'.while($arraybank=mysql_fetch_array($querybank)){
.'<tr>
<td>'.$arraybank['bank'].'</td>
<td>'.$arraybank['norek'].'</td>
<td>'.$arraybank['ket'] .'</td>
</tr>'.}.
'id order :'.$order_id.',shop again! ';

    $headers =  'MIME-Version: 1.0' . "\r\n".
                'Content-Type: text/html; charset=ISO-8859-1' . "\r\n".
                'From: shoesshe <cs@shoesshe.com>' . "\r\n" .
                'Reply-To: shoesshe <cs@shoesshe.com>' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

  }
}

i was try like that but 我曾经尝试过但是

Parse error: syntax error, unexpected T_WHILE in /model/email.php on line 34 解析错误:语法错误,第34行的/model/email.php中出现意外的T_WHILE

i was try before using text only and thats work, i just want to send data to that mail with table using while.. 我只是在使用文本之前尝试过,多数民众赞成在工作,我只想使用while将数据发送到带有表的邮件。

anyone can help me? 有人可以帮助我吗?

The problem is in your message string. 问题出在您的消息字符串中。 You can't put a while in there. 你不能在那里放一会儿。 This will work: 这将起作用:

$message = 'thanks :) this is bank account
<table>
  <tr>
    <th>Bank</th>
    <th>Number</th>
    <th>Other</th>
  </tr>';
while($arraybank=mysql_fetch_array($querybank)){
$message .='
<tr>
<td>'.$arraybank['bank'].'</td>
<td>'.$arraybank['norek'].'</td>
<td>'.$arraybank['ket'] .'</td>
</tr>';
}

$message .= 'id order :'.$order_id.',shop again! ';

As you can see, the while will add more text to your string in each loop. 如您所见,while将在每个循环中向字符串添加更多文本。 You were concatenating the while before, and it would not work. 您在之前连接了一段时间,这是行不通的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM