2017-09-14 45 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

感謝它的工作 –