申し訳ありませんが、これは説明が不適切な場合は、比較的新しいです。PHPのボタンでmysqlの結果データを含むhtmlテーブルを電子メールで送信するにはどうすればよいですか?
私は、日付範囲でフィルタリングされたmysqlデータの結果をhtmlテーブルに表示するWebツールを開発しています。私は、ユーザーがテーブルデータを送信する電子メールアドレスを入力できるようにする入力とボタンを持っています。問題は、電子メールを送信するPHPページに正しくhtmlテーブルのデータを渡すのに問題があることです。
AJAXとJavascriptでさまざまな方法を試しましたが、何も問題はありません。ある時点で、私はテーブルデータを渡すことができましたが、入力された電子メールは受け取りませんでした(またはその逆)。両方同時にはありません。私は入力された電子メールとhtmlテーブル内のデータの両方を、好ましくはテーブルフォーマットを予約してよりクリーンな外観にすることが望ましい)を渡すことができる必要があります。どんな助けや洞察も大歓迎です。このコードが不適切であるか間違っている場合は謝罪してください。
関連PHP:
<!-- download2csv button -->
<div>
<form action="getCSV.php" method="post">
<input type="hidden" name="csv_text" id="csv_text_computers">
<button class="btn btn-app btn-primary btn-xs no-radius" type="submit" onclick="getCSVDataComputers()">
<i class="icon-save"></i></button>
</form>
<!-- email button -->
<form action="mailto.php" method="post">
Email: <input type="text" name="einame" id="eiid" placeholder="[email protected]">
<button class="btn btn-app btn-info btn-xs no-radius" type="submit" name="ebname" id="ebid" onclick="mailer()">
<i class="icon-envelope"></i></button>
</form>
</div>
</div>
<!-- data table header -->
<div class="table-responsive">
<table id="table-computers1" name="table-computers" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Item Name</th>
<th>RFID Number</th>
<th>Link</th>
<th>Delivery Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($infocoms as $infocom)
{
//variables for glpi url
$itemtype = $infocom['itemtype'];
$items_id = $infocom['items_id'];
$url = "https://null.null.com/front/" . $itemtype. ".form.php?id=" . $items_id;
?>
<tr>
<?php
// database connection
$conn = mysqli_connect('null', 'null', 'null');
mysqli_select_db($conn, 'glpi');
if ($infocom['itemtype'] == "peripheral") {
$query = "SELECT glpi_peripherals.name AS devicename, TRIM(LEADING '0' FROM glpi_peripherals.otherserial) AS otherserial FROM glpi_peripherals INNER JOIN glpi_infocoms ON glpi_peripherals.id = glpi_infocoms.items_id WHERE glpi_infocoms.items_id = $infocom[items_id] AND glpi_infocoms.itemtype = 'peripheral'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$devices = $result->fetch_assoc();
echo "<td>$devices[devicename]</td>";
echo "<td><center>$devices[otherserial]</center></td>";
} elseif ($infocom['itemtype'] == "computer") {
$query = "SELECT glpi_computers.name AS compname, TRIM(LEADING '0' FROM glpi_computers.otherserial) AS otherserial FROM glpi_computers INNER JOIN glpi_infocoms ON glpi_computers.id = glpi_infocoms.items_id WHERE glpi_infocoms.items_id = $infocom[items_id] AND glpi_infocoms.itemtype = 'computer'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$computers = $result->fetch_assoc();
echo "<td>$computers[compname]</td>";
echo "<td><center>$computers[otherserial]</center></td>";
} elseif ($infocom['itemtype'] == "monitor") {
$query = "SELECT glpi_monitors.name AS viewname, TRIM(LEADING '0' FROM glpi_monitors.otherserial) AS otherserial FROM glpi_monitors INNER JOIN glpi_infocoms ON glpi_monitors.id = glpi_infocoms.items_id WHERE glpi_infocoms.items_id = $infocom[items_id] AND glpi_infocoms.itemtype = 'monitor'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$monitors = $result->fetch_assoc();
echo "<td>$monitors[viewname]</td>";
echo "<td><center>$monitors[otherserial]</center></td>";
} elseif ($infocom['itemtype'] == "networkequipment") {
$query = "SELECT glpi_networkequipments.name AS netname, TRIM(LEADING '0' FROM glpi_networkequipments.otherserial) AS otherserial FROM glpi_networkequipments INNER JOIN glpi_infocoms ON glpi_networkequipments.id = glpi_infocoms.items_id WHERE glpi_infocoms.items_id = $infocom[items_id] AND glpi_infocoms.itemtype = 'networkequipment'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$networks = $result->fetch_assoc();
echo "<td>$networks[netname]</td>";
echo "<td><center>$networks[otherserial]</center></td>";
} elseif ($infocom['itemtype'] == "printer") {
$query = "SELECT glpi_printers.name AS printname, TRIM(LEADING '0' FROM glpi_printers.otherserial) AS otherserial FROM glpi_printers INNER JOIN glpi_infocoms ON glpi_printers.id = glpi_infocoms.items_id WHERE glpi_infocoms.items_id = $infocom[items_id] AND glpi_infocoms.itemtype = 'networkequipment'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$printers = $result->fetch_assoc();
echo "<td>$printers[printname]</td>";
echo "<td><center>$printers[otherserial]</center></td>";
} else {
// error handling for null entries
echo "1 or more items were not found";
}
// end data loop and close mysql connection
mysqli_close($conn);
?>
<td><a target=_blank href=$url><?php echo $url; ?></a></td>
<td><center><?php echo $infocom['ddate']; ?></center></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
</div>
<?php
} else {
echo "<center><p style='font-size:125%;'>Please select a date range to submit.</p></center>";
}
error_log("\n");
?>
関連Javascriptを:
<script type="text/javascript">
jQuery(function($) {
var oTable1 = $('#table-computers').dataTable({
"aLengthMenu": [[10, 25, 100, -1], [10, 25, 100, "All"]],
"iDisplayLength": -1,
"aoColumns": [
{ "bSortable": true },
null, null,null,
] });
})
function getCSVDataComputers(){
var csv_value=$('#table-computers').table2CSV({delivery:'value'});
$("#csv_text_computers").val(csv_value);
}
</script>
<script type="text/javascript">
function mailer()
{
var tableContent=document.getElementById("table-computers").innerHTML;
alert(tableContent); // This works, but data does not echo in mailto.php
$.post('mailto.php',{content:tableContent},function(data) {
});
}
</script>
mailtoのPHPページ:
<?php
$mailto = $_POST['einame'];
$table = $_POST['tableContent'];
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Test <[email protected]>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (isset($mailto)) {
mail($mailto,"GLPI Notifications",$table,$headers);
echo "Mail sent successfully to $mailto." . "\r\n";
} else {
echo "Mail was not sent." . "\r\n";
}
?>
<br>
<a href="blank.php">Home Page</a>
<br>
<?php
echo $table; // Displays nothing
error_log("\n");
?>
この部分では、 $ _POST ['content'] 'と' $ _POST ['email'] 'を送信しないでしょうか? – Rasclatt