现在我想生成一个客户凭证,然后将其发送到特定的个人电子邮件id。我已经使用phpmailer完成了基本的邮件功能。现在,我收到了一封电子邮件,但没有收到mysql数据。我试了些东西。但它不起作用。例如,如果我单击凭证id 7,则它将显示凭证id 7的全部详细信息。我想把那个特定的(凭证id 7)数据发送到电子邮件。
$body = file_get_contents('print.php');
在这里,我如何将mysql_fetch记录插入电子邮件正文页。。。?我希望有人能告诉我这个问题的答案。。
这是我的print.php页面编码:
if(isset($_GET['id']))
{
$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query ( "SELECT * FROM voucher WHERE voucherno = $id" );
$row = mysql_fetch_object($query);
echo mysql_error();
<tr>
<td width=193 height=40 class=rightstyle>Voucher Number : </td>
<td width=229 class=leftstyle> $row->voucherno </td>
<td width=234 class=rightstyle>Reference Number : </td>
<td width=234 class=leftstyle> $row->reference </td>
</tr>
}
仍然有很多数据是从mysql数据库中获取的。所以我想在这个页面上发一封邮件(包括mysql数据)。。。
最佳答案
<?php
ob_start();
//smtp detail start
require_once ('class.phpmailer.php' );
$mail=new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
//SMTP detail from here
//$mail->SMTPSecure = "ssl";
$mail->Host = "yourhostname"; // sets GMAIL as the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "you@yourdomain.com";
$mail->Password = "yourpassword";
//$mail->SMTPDebug=1;
//SMTP deatil end
//smtp mail end
if(isset($_GET['id']))
{
$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query ( "SELECT * FROM voucher WHERE voucherno = $id" );
while($row = mysql_fetch_object($query))
{
$strMessage = "<tr>
<td width=193 height=40 class=rightstyle>Voucher Number : </td>
<td width=229 class=leftstyle> $row->voucherno </td>
<td width=234 class=rightstyle>Reference Number : </td>
<td width=234 class=leftstyle> $row->reference </td>
</tr>";
}
// $flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader); // @ = No show error //
$mail->FromName = "your name";
$mail->From = "your mail id";
$mail->ContentType ="text/html";
$mail->AddAddress('test@testing.com');//mail will be send on this email
$mail->Subject='customer voucher';
$mail->Body = $strMessage;
if($mail->Send())
{
echo "mail send.";
}
else
{
echo "Cannot send mail.";
}
}
ob_flush();
?>