gpt4 book ai didi

php - 如何通过电子邮件发送 mysql 获取记录 php 页面

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

当我通过电子邮件发送页面时,它会显示 php 代码。它不会从 mysql 获取详细信息,然后我根据特定的凭证 ID 获取 mysql 记录。如何通过电子邮件发送mysql获取记录页面?看看这个编码..

<?php
require_once('phpmailer/class.phpmailer.php');
include("phpmailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = file_get_contents('print.php[HERE HOW CAN I FETCH MYSQL RECORDS OF PARTICULAR VOUCHER ID]');
$body = preg_replace('/\/b]/','',$body);


$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "myemail@rediff.com"; // Email username
$mail->Password = "mypassword"; // Email password

$mail->SetFrom('myemail@rediff.com', 'Subject Line');

$mail->AddReplyTo("youremail@rediff.com","Subject Line");

$mail->Subject = "Full Subject Line";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$email = $_POST['email'];
$mail->AddAddress($email);

if(!$mail->Send()) {
echo "<div align=center style=\"color:#FF0000; font-family: 'Times New Roman', Times, serif; font-size: 26px;\">Could not send email to : . $mail->ErrorInfo</div>";
} else {
echo "<script> alert('Mail successfully sent to $email') </script>";
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=mainpage.php">';
exit;
}
?>

我想根据特定的凭证 ID 获取 mysql 记录。如果用户单击优惠券 ID 10,它将显示优惠券 ID 10 的完整详细信息。然后我想通过电子邮件发送该页面。现在我收到一封电子邮件。但我没有得到该特定 id 的 mysql 记录。如何做到这一点?

最佳答案

我在这里发布了另一个问题(send an email with mysql fetch records)。我从那篇文章中得到了帮助。所以,我在下面发布了正确的答案。

    <?php
ob_start();
require_once('phpmailer/class.phpmailer.php');
include("phpmailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "myemail@rediff.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password

include("config.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);
$strMessage = "<table>
<tr>
<td>Voucher Number : </td>
<td> $row->voucherno </td>
<td>Reference Number : </td>
<td> $row->reference </td>
</tr>
</table>";

$mail->SetFrom('myemail@rediff.com', 'FromName');

$email = mysql_real_escape_string($_POST['email']);
$mail->AddAddress($email ,"$row->gname, $row->city");
$mail->Subject = "Subject Line";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->Body = $strMessage;

if($mail->Send())
{
echo "<script> alert('Mail succesfully sent to $email.'); </script>.";
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=mainpage.php">';
exit;
}
else
{
echo "<div align=center style=\"color:#FF0000; font-family: 'Times New Roman', Times, serif; font-size: 26px;\"> Cannot send mail. $mail->ErrorInfo. </div>";
}
}
ob_flush();
?>

关于php - 如何通过电子邮件发送 mysql 获取记录 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20297152/

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