提问人:StereoMC 提问时间:9/20/2020 最后编辑:JsowaStereoMC 更新时间:9/20/2020 访问量:136
如何从另一个文件中获取PHP变量?
How to get PHP variable from another file?
问:
我正在尝试在 xampp 上使用 PHPMailer 制作一个忘记密码系统。
但是当我发送电子邮件时,电子邮件正文是一个html邮件模板,我从另一个文件中得到的,我有问题,因为我不知道我应该如何获取变量的数据并将其发送到文件以将其用于邮件中的链接。
我尝试了这个命令,但没有奏效。$mail->Body = file_get_contents('mail_template.php');
$url
mail_template.php
include 'filename.php';
代码如下:
if (isset($_POST["submitButton"])) {
$emailTo = $_POST["email"];
$code = md5(uniqid(rand(), true));
$query = $con->prepare("INSERT INTO resetpasswords(code,email) VALUES('$code', '$emailTo')");
$query->execute();
if (!$query) {
exit("Something went wrong...");
}
$mail = new PHPMailer(true);
try {
//Server settings // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('[email protected]', 'Email');
$mail->addAddress($emailTo); // Add a recipient
$mail->addReplyTo('[email protected]', 'No reply');
// Content
$url = "http://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]) . "/resetPassword/code/$code";
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Reset your password!';
$mail->Body = file_get_contents('mail_template.php');
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Error: {$mail->ErrorInfo}";
}
header("refresh:10;url=login.php");
}
所以从这个php文件中,我想把数据发送到$url
mail_template.php
这可能吗?
答:
0赞
Temidayo Dtuzzy Omotayo
9/20/2020
#1
要在 php 中将数据发送到另一个 url,您必须尝试以下 url:
`[email protected]`
然后在一个空mail_template.php里做——
<?php
if (isset($_GET['data'])) {
$test = $_GET['data'];
//print the data added to the url
echo $test;
}
?>
评论
mail_template.php
mail_template.php
<a data-click-track-id="37" href="<?php echo $url; ?>" style=".........">Reset Password </a>