我希望你能幫助我把它,我有這樣的代碼:創建XLS,並通過電子郵件
<?php
session_start();
include('includes/connect.php');
header("Content-Type: application/vnd.ms-excel charset=utf-8");
header("Content-Disposition: attachment; filename=consultores.xls"); //File name extension was wrong
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
$query = $_SESSION['query'];
$qry = $mysqli->query($query);
echo $mysqli->error;
?>
<body style="border: 1px solid #ccc">
<?php
echo '<table class="table table-striped">';
?>
<tr>
<th>
Apellido
</th>
<th>
Nombre
</th>
<th>
E-Mail
</th>
<th>
Teléfono Celular
</th>
<th>
CV
</th>
<th>
Foto
</th>
<?php
$query1 = "SELECT * FROM ind_exp ORDER BY nombre ASC";
$qry1 = $mysqli->query($query1);
while($f1 = $qry1->fetch_assoc())
{
echo '<th>';
echo 'Experiencia en Industrias de: '.mb_convert_encoding($f1['nombre'],'utf-16','utf-8');
echo '</th>';
}
$query2 = "SELECT * FROM proy_exp ORDER BY nombre ASC";
$qry2 = $mysqli->query($query2);
while($f2 = $qry2->fetch_assoc())
{
echo '<th>';
echo 'Experiencia en Proyectos de: '.mb_convert_encoding($f2['nombre'],'utf-16','utf-8');
echo '</th>';
}
$query3 = "SELECT * FROM rol_exp ORDER BY nombre ASC";
$qry3 = $mysqli->query($query3);
while($f3 = $qry3->fetch_assoc())
{
echo '<th>';
echo 'Experiencia en Roles de: '.mb_convert_encoding($f3['nombre'],'utf-16','utf-8');
echo '</th>';
}
?>
</tr>
<?php
while($f = $qry->fetch_assoc())
{
$mail = $f['email'];
foreach($f as $key=>$value)
{
$f[$key] = mb_convert_encoding($value,'utf-16','utf-8');
}
?>
<tr>
<td>
<?php
echo $f['apellido'];
?>
</td>
<td>
<?php
echo $f['nombre'];
?>
</td>
<td>
<?php
echo $f['email'];
?>
</td>
<td>
<?php
echo $f['cel'];
?>
</td>
<td>
<?php
echo 'http://litup.cl/registro/'.$f['cv'];
?>
</td>
<td>
<?php
echo 'http://litup.cl/registro/'.$f['foto'];
?>
</td>
<?php
$query1 = "SELECT * FROM ind_exp ORDER BY nombre ASC";
$qry1 = $mysqli->query($query1);
while($f1 = $qry1->fetch_assoc())
{
echo '<td>';
$query3 = "SELECT * FROM rel WHERE id_reg = '$mail' AND tipo_rel = 'iec'";
$qry3 = $mysqli->query($query3);
//echo $qry3->num_rows;
//echo $query3;
while($f3 = $qry3->fetch_assoc())
{
//echo $f1['nombre'].' - '.$f3['nombre_ext'];
if($f1['nombre'] == $f3['nombre_ext'])
{
$aux = $f1['nombre'];
$cosa = mb_convert_encoding($aux,'utf-16','utf-8');
echo ' '.$cosa.' ';
}
if($f3['otro']=='si' && $f1['nombre']== 'Otra Industria')
{
$aux = $f3['nombre_ext'];
$cosa = mb_convert_encoding($aux,'utf-16','utf-8');
echo ' '.$cosa.' ';
}
}
//echo 'Industria de apoyo: '.$f1['nombre'];
echo '</td>';
}
$query1 = "SELECT * FROM proy_exp ORDER BY nombre ASC";
$qry1 = $mysqli->query($query1);
while($f1 = $qry1->fetch_assoc())
{
echo '<td>';
$query3 = "SELECT * FROM rel WHERE id_reg = '$mail' AND tipo_rel = 'pec'";
$qry3 = $mysqli->query($query3);
//echo $qry3->num_rows;
//echo $query3;
while($f3 = $qry3->fetch_assoc())
{
//echo $f1['nombre'].' - '.$f3['nombre_ext'];
if($f1['nombre'] == $f3['nombre_ext'])
{
$aux = $f1['nombre'];
$cosa = mb_convert_encoding($aux,'utf-16','utf-8');
echo ' '.$cosa.' ';
}
if($f3['otro']=='si' && $f1['nombre']== 'Otro Proyecto')
{
$aux = $f3['nombre_ext'];
$cosa = mb_convert_encoding($aux,'utf-16','utf-8');
echo ' '.$cosa.' ';
}
}
//echo 'Industria de apoyo: '.$f1['nombre'];
echo '</td>';
}
$query1 = "SELECT * FROM rol_exp ORDER BY nombre ASC";
$qry1 = $mysqli->query($query1);
while($f1 = $qry1->fetch_assoc())
{
echo '<td>';
$query3 = "SELECT * FROM rel WHERE id_reg = '$mail' AND tipo_rel = 'rec'";
$qry3 = $mysqli->query($query3);
//echo $qry3->num_rows;
//echo $query3;
while($f3 = $qry3->fetch_assoc())
{
//echo $f1['nombre'].' - '.$f3['nombre_ext'];
if($f1['nombre'] == $f3['nombre_ext'])
{
$aux = $f1['nombre'];
$cosa = mb_convert_encoding($aux,'utf-16','utf-8');
echo ' '.$cosa.' ';
}
}
//echo 'Industria de apoyo: '.$f1['nombre'];
echo '</td>';
}
?>
</tr>
<?php
}
echo '</table>';
echo $mysqli->error;
?>
</body>
有了這完全是出口到XLS,但現在我需要發送此XLS作爲附件一封電子郵件,但我有點失落。我希望你能幫助我。
如果您需要任何其他信息告訴我。
在此先感謝
我可以建議,如果你想要一個'完美的XLS'你嘗試使用PHPExcel而不是導出一個HTML文件,因爲這是一個可怕的方式來建立一個可靠的XLS – RiggsFolly
甚至一個簡單的CSV文件將更可靠 – RiggsFolly