php - 如何在 php 中为 send_mail 生成 unique_id
问题描述
目前我们有 send_mail 和这个函数在不同的文件中调用。
我们有 auto_mailer 将报告订阅电子邮件与以编程方式生成的电子邮件地址连接起来。
我的任务是生成 uniqueId,这样我们就不必在调用 send_mail 函数的每个文件上更改/手动添加 send_mail 参数/参数。
生成的 uniqueId 必须代表调用它的 send_mail 函数。
我们已经尝试使用 debug_backtrace() 并通过 sha1() 转换它以生成 uniqueId,但问题是未来代码的变化。
我们已经尝试使用 send_mail 参数/参数并通过 sha1() 将其转换以生成 uniqueId,但问题是参数/参数数据是动态的。
这是示例代码:
$subject = 'Tickets 1st QTR 2020';
// 1st scenario
function send()
{
send_mail('',$recipient.'', "Reports Guy", $sender, $subject);
}
function send2()
{
send_mail('',$recipient.'', "Reports Guy", $sender, $subject);
}
// 2nd scenario: uniqueId shoud remain the same even there's a change/update in php code
function send()
{
// must be same uniqueId
send_mail('',$recipient.'', "Reports Guy", $sender, $subject);
}
function send3()
{
// must be different uniqueId
send_mail('',$recipient.'', "Reports Guy", $sender, $subject);
}
function send2()
{
// must be same uniqueId
send_mail('',$recipient.'', "Reports Guy", $sender, $subject);
}
function send_mail($module,$to_email,$from_name,$from_email,$subject,$contents,$cc='',$bcc='',$attachment='',$emailid='',$logo='',$set='',$filename='')
{
global $DEV_TEST_ENV;
global $DEV_TEST_EMAIL;
global $DEV_FROM_EMAIL;
// add code here that generate and check uniquedId in tbl_subscriptions
// create new entry if not exist else continue to send.
$mail_log = preg_replace("/\s{2}/", "", nl2br("'".$module."','".$to_email."','".str_replace(array("'", "\n"), "", $from_name)."','".$from_email."','".str_replace(array("'", "\n"), "", $subject)."','','".$cc."','".$bcc."','".$attachment."','".$emailid."','".$logo."'"));
return $mail_error;
}
例子:
在上面的场景 #1 中,假设 send2() 在第 22 行并生成 uniquedId - 123asd。
在场景#2 send2() 被移动到第 32 行或参数被更改,我如何生成相同的 uniqueId?
解决方案
推荐阅读
- python - 自动加载表上的所有 SQLAlchemy 查询是否在导入后运行?
- javascript - 在页面离开事件和返回按钮之前
- python - 为什么python不能显示sin函数的准确值?
- javascript - 使用 vue.js 链接来自 mongoDB 的两个集合
- django - Django zappa 应用程序功能的模块化路径?不知道是哪一个
- c# - 在postgres Npgsql c#中执行多个插入查询
- protocol-buffers - 解码 Protobuf 响应
- python - (Discord Bot) on_raw_reaction_add(payload) 问题(票务系统)
- node.js - 快速重定向路线到另一条路线
- html - 如何使用点 html 保存文件夹以显示 html 符号?