dse84825 2015-09-21 11:37
浏览 33

通过电子邮件发送从db填充的表单数

I have a form where the name and details are filled and iam able to collect the details filled and email the data.But in the form one field is filled from DB which is "comments" field.

        <?php
    $sql = "SELECT * FROM comments WHERE id = no ";
    $result = mysqli_query ($conn,$sql) or die (mysqli_error ());
    $count = 1;
    while ($row = mysqli_fetch_array ($result))
    {?>
   <tr>
   <td valign="top" >
   <label for="old_comments">comments <?php   
   echo $count 
   ?>:</label>
    </td>
   <td style="
   padding-bottom: 0px;">
   <input type="text" name="old_comments" value="<?php echo $row ['updates']; ?> "
    readonly maxlength="500" size="30" style=" width: 710px; ">
<br>
<span class="helptext" >Previous comments.</span>
</td>
    </tr>
     <?php
     $count = $count + 1;
    }
    ?>

There will be number of comments but here only one recent comment is getting inserted into the mail.I need all the comments in the db for particular post id table to be inserted into the mail body.PHP code which iam using to send the email:

     <?php
 if(isset($_POST['email'])) {
 $email_to = mail@domain.com;
 $email_subject = omments;
 function died($error) {
 echo "We are very sorry, but there were error(s) found with the form you submitted. ";
       die();
 }
 // validation expected data exists
 if(!isset($_POST['old_comments'])) {
 }
 $old_comments = $_POST['old_comments]; // required
 $error_message = "";
 $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 $string_exp = "/^[A-Za-z .'-]+$/";
 if(strlen($error_message) > 0) {
 died($error_message);
 }
 $email_message = "Comments";
 function clean_string($string) 
{
 $bad = array("content-type","bcc:","to:","cc:","href");
 return str_replace($bad,"",$string);
 }
 $email_message .= "Previous Comments: ".clean_string($Comments)."

";
 // create email headers
 $headers = 'From: '.$email_from."
".

 'X-Mailer: PHP/' . phpversion();
  @mail($email_to, $email_subject, $email_message, $headers);  
  ?>
  <?php
  }
  ?>

Can anyone help this one out.Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

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