gpt4 book ai didi

php - 发送带有 mysql 获取记录的电子邮件

转载 作者:行者123 更新时间:2023-11-29 04:45:07 25 4
gpt4 key购买 nike

现在我想生成一张客户凭证,然后将其发送到特定的人的电子邮件 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();
?>

关于php - 发送带有 mysql 获取记录的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com