gpt4 book ai didi

来自 mysql 的 php 邮件模板变量

转载 作者:行者123 更新时间:2023-11-30 00:00:46 24 4
gpt4 key购买 nike

嗨,我正在尝试在 mysql 中制作电子邮件模板,但是如何将变量从 mysql 解析到 php 脚本?

示例:

如果我在 mysql 中有一行名为“主题”和“标题”,示例文本如下:

你好$UserFirstName

这是 $domain 的自动通知系统。这封电子邮件旨在通知您,新账单已添加到您的帐户

<小时/>

我使用mysqli连接

这是我现在使用的 php 文件源,但想在 mysql 中拥有模板:

<?php

$gp['template']->get_header();

if ($_SESSION['userlevel'] > 3) {

if ( isset ( $_POST['submit'] ) ) {

if (empty($_POST["name"]))
{$nameErr = $gp['lang_ALERT_NAME_REQUIRED'];
}
else {
if (empty($_POST["username"]))
{$usernameErr = $gp['lang_ALERT_USERNAME_REQUIRED'];
}
else {
if (empty($_POST["email"]))
{$emailErr = $gp['lang_ALERT_EMAIL_REQUIRED'];
}
else {

$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$website = $_POST['website'];
$password = $_POST['password'];
$userlevel = "1";
$active = "1";
// Create a random salt
$random_salt = $gp['user']->createSalt();
// Create salted password (Careful with the chilli)
$password = hash('sha256', $random_salt . $password . $random_salt);
$username = $_POST['username'];
$email = $_POST['email'];
if ($insert_stmt = $gp['mysqli']->prepare("INSERT INTO ".$gp['settings_db_prefix']."users (name, username, email, password, salt, userlevel, active, address, city, zip, country, website) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))
{
$insert_stmt->bind_param('ssssssssssss', $name, $username, $email, $password, $random_salt, $userlevel, $active, $address, $city, $zip, $country, $website);
$insert_stmt->execute();

// Send Email to user

$urlpath = $gp['settings_url'];
$password = $_POST["password"];
$userdata_name = $gp['session_userdata']['name'];
$mail_to = $_POST["email"];


$mail_from = $gp['settings_mail_from'];
$mail_subject = 'GamePanel - New user';

$message = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>'.$mail_subject.'</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body bgcolor="#758899">
<center>

<table border="0" style="display: inline-block;line-height: 39px;margin: 0 0 16px 0;padding: 7px 16px;padding-top: 7px;letter-spacing: -1px;color: #fff;background-color: #21282f;font-family: Purista,sans-serif;font-size: 36px;font-style: normal;font-weight: bold;text-transform: uppercase;">
<tr>
<td height="81"><img src="http://'.$urlpath.'/themes/default/images/logo_white.png" width="315" /></td>
</tr>
</table>

<table bgcolor="" align="center" cellpadding="0" cellspacing="0" width="100%" border="0" style="padding: 0px; border: 0px; padding-top: 0px;">
<tr>
<td height="218">
<table bgcolor="#758899" align="center" cellpadding="0" cellspacing="0" border="0" style="padding:40px 10px 40px 10px;">
<tr>
<td>
<table bgcolor="" align="center" cellpadding="0" cellspacing="0" width="600" border="0" style="padding:0px;border:0px;">
<tr>
<td bgcolor="" style="background-color: #191c20;color: #d5dde5;padding: 8px 12px; margin-top: 0px;font-family: Purista,sans-serif;font-size: 16px;font-style: normal;font-weight: 700;">
'.$mail_subject.'
</td>
</tr>
<tr>
<td bgcolor="" style="float: left;width: 685px;background-color: #2e3741;padding: 10px 10px 0;margin-top: 1px;color: #FFFFFF; padding-bottom:10px;">
To login go to <a href="'.$urlpath.'" style="color:#d5dde5;">'.$urlpath.'</a><br /><br />
Your password is: '.$_POST["password"].'
<br />
<br />
Please login and update your information on Account / My Account.
<br /><br />Best Regards GamePanel.
</td>
</tr>
<tr>
<td bgcolor="" style="float: left;width: 700px;background-color: #3c4655;margin-bottom: 25px;margin-top: 1px; padding-left:5px; padding-top:5px; padding-bottom:5px;color: #FFFFFF;font-family: Purista,sans-serif;font-weight: bold; font-size:14px;">
Copyright © 2014 <a href="http://game-panel.dk" style="color:#d5dde5;">GamePanel</a>, All rights reserved.
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
';

$headers = "From: ".$mail_from."\r\n";
$headers .= "Content-type: text/html\r\n";
mail($mail_to, $mail_subject, $message, $headers);

header("Location: ?success=1");
}
else
{
header("Location: ?registrationfailed=1");
}
}
}
}
}

?>

最佳答案

如果我理解正确,您可以尝试用这种方式替换占位符(根据需要编辑此代码):

$templateString = $gp['mysqli']->query('select template from tpl_table')->template;
$bodyMessage = str_replace(array('%TITLE%','%FOO%'), array($yourTitle,$someFoo), $templateString);

mysql中的模板格式应该是这样的:

<html><head><title>%TITLE%</title></head><body>Bar: %FOO%</body></html>

希望这是您正在寻找的

关于来自 mysql 的 php 邮件模板变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25048300/

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