2017-09-14 39 views
-1

我使用的形式 “addrow” 和 “deleterow”:的foreach发送邮件体

function addRow(tableID) { 
    var table = document.getElementById(tableID); 
    var rowCount = table.rows.length; 
    if(rowCount < 5){       // limit the user from creating fields more than your limits 
     var row = table.insertRow(rowCount); 
     var colCount = table.rows[0].cells.length; 
     for(var i=0; i<colCount; i++) { 
      var newcell = row.insertCell(i); 
      newcell.innerHTML = table.rows[0].cells[i].innerHTML; 
     } 
    }else{ 
     alert("Maximum Passenger per ticket is 5."); 

    } 
} 

send.php着发送电子邮件,给了我这个错误:

PHP Parse error: syntax error, unexpected '.' in /home/metroloj/public_html/form/dene1/send.php on line 52

在这条线:

<?php foreach($BX_NAME as $a => $b){ ?> 

我无法添加php发送此代码示例部件:

<?php foreach($BX_NAME as $a => $b){ ?> 
    <tr> 
    <p> 
     <td> 
      <?php echo $a+1; ?> 
     </td> 
     <td> 
      <label>Name</label> 
      <input type="text" readonly="readonly" name="BX_NAME[$a]" value="<?php echo $BX_NAME[$a]; ?>"> 
     </td> 

    </p> 
    </tr> 
<?php } ?> 
<?php foreach($BX_NAME as $a => $b){ ?> 

<input type="text" readonly="readonly" name="BX_NAME[$a]" value="<?php echo $BX_NAME[$a]; ?>"> 

$mail->Body .= '<input type="text" readonly="readonly" name="BX_NAME[$a]" value="'. strip_tags($_POST['BX_NAME[$a]']) .'">'; 
+0

是否使用[PHPMailer的(https://github.com/PHPMailer/ PHPMailer的)? – showdev

回答

0

这里可能还有其他的问题,但我只是讲一般的PHP语法。
打开和关闭PHP标签必须用于混合内容(HTML和PHP一起)。

Everything outside of a pair of opening and closing tags is ignored by the PHP parser which allows PHP files to have mixed content. This allows PHP to be embedded in HTML documents, for example to create templates.

This works as expected, because when the PHP interpreter hits the ?> closing tags, it simply starts outputting whatever it finds... until it hits another opening tag...

请参阅Escaping from HTML

此外,在您的foreach示例中,$BX_NAME[$a]$b具有相同的值。

foreach (array_expression as $key => $value)

所以array_expression[$key]是一样的$value


例如:

<?php 
foreach ($BX_NAME as $a => $b) { 
    ?><tr> 
     <td><?=$a+1?></td> 
     <td> 
      <label>Name</label> 
      <input type="text" readonly="readonly" name="<?=$b?>" value="<?=$b?>"> 
     </td> 
    </tr><?php 
} 

当建立一个字符串,使用.来连接:

foreach ($BX_NAME as $a => $b){ 

    ?><input type="text" readonly="readonly" name="<?=$b?>" value="<?=$b?>"><?php 
    $mail->Body .= '<input type="text" readonly="readonly" name="'.$b.'" value="'.strip_tags($_POST[$b]).'">'; 

} 
+0

感谢它的工作 –