我需要将我的代码结果发送到邮件中。 如果我写html代码,它全部显示在我的电子邮件中,但是如果我写了php代码 - 它没有显示。
在我的浏览器中它可以工作,但在我的电子邮件中它只显示“资源ID#7”。
<?php
include_once("include.php");
include_once("p_bulan.php");
require_once('class.phpmailer.php');
$runSQL = "select a.id_client, a.nama_cpw, ifnull(a.tlp_mobile_cpw,'belum-diinput')tlp_mobile_cpw, ifnull(a.nama_cpp,'belum-diinput')nama_cpp, ifnull(a.tlp_mobile_cpp,'belum-diinput')tlp_mobile_cpp, a.tgl_rencana, b.tgl_janjiawal, b.tgl_janjiakhir, b.barang, b.keterangan, ifnull(c.nama,'-')nama
from client a
left join jadwal_fitting_new b on a.id_client=b.id_client
left join pegawai c on a.id_pegawai=c.id_pegawai
where a.id_client=b.id_client and b.tgl_janjiakhir BETWEEN '$tanggal' AND '$tanggal2'
order by id_client desc";
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->IsSendmail(); // telling the class to use SendMail transport
$body =
$res=mysql_query($runSQL);
//echo $runSQL;
while($rec=mysql_fetch_array($res))
{
$ccc++;
if ($ccc%2 > 0){ $color='#EBEFFA'; }else{ $color='#D7E0F4'; };
echo "<table><tr bgcolor=$color onmouseover=bgColor=\'#FDD0D8\' onmouseout=bgColor=\'$color\' valign=top>
<td align='center'>".($ccc)."</td>
<td align=center> $rec[nama_cpw] </td>
<td align=center> $rec[tlp_mobile_cpw]</td>
<td align=center> $rec[nama_cpp] </td>
<td align=center> $rec[tlp_mobile_cpp] </td>
<td align=center> $rec[tgl_rencana] </td>
<td align=center> $rec[tgl_janjiawal] </td>
<td align=center> $rec[tgl_janjiakhir] </td>
<td> $rec[barang] </td>
<td> $rec[keterangan] </td>
<td> $rec[nama]</td>
</tr>";
}
echo "<tr bgcolor=$color onmouseover=bgColor=\'#FDD0D8\' onmouseout=bgColor=\'$color\' valign=top>
</tr>
</table>
</font>
</table></br>
<table align='center' width='1002' height='79' border='0'>
<tr align='center' >
<td height='23'>Dibuat oleh,</td>
<td>Diperikasa oleh,</td>
</tr>
<tr>
<td height='23'> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr align='center'>
<td height='23'>(Admin Fitting)</td>
<td>(KaBag. Gudang)</td>
</tr>
</table>";
$mail->AddReplyTo('admin@alfin.com', 'admin');
$mail->AddAddress('alfin@gmail.com', 'zalfinm');
$mail->SetFrom('admin@alfin.com', 'admin');
$mail->AddReplyTo('admin@alfin.com', 'admin');
$mail->Subject = 'test';
$mail->AltBody = 'ini isi email'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
please help me
答案 0 :(得分:0)
如果内容类型标题有效,则会显示HTML代码
'Content-type: text/html;'
但是php代码不会显示在邮件中,你可以尝试把它放在一个字符串中并在php字符串之前和之后添加它
<pre>
<code>
// your code
</code>
</pre>