从电子邮件调用 php 函数

Call php function from email

我有一个功能:

public function doSomething($uniqueID)
{
    $model = new model();
    $model->someFunction($uniqueID);

    $this->goSomewhere();
}

它所做的只是更新数据库中的一个字段。但我正在努力。 该函数的过程是什么,它将在数据库中创建一行并发送一封电子邮件要求批准/拒绝。

我需要它,当用户点击批准/拒绝时,它会转到传递 ID 的 doSomething 函数。 href 看起来像“http://localhost/doSomething/uniqueID”,但它失败了 - 目前 returns 没有找到它的视图文件。

如何从 html 电子邮件 link 执行功能?

您需要创建一个带有参数的 link: http://xxxxxx/pageDoSomething?uniqueID=123

如果参数正确,则在文件中执行函数!

pageDoSomething.php的内容:

public function doSomething($uniqueID)
{
    $model = new model();
    $model->someFunction($uniqueID);

    $this->goSomewhere();
}

if (!empty($_GET['uniqueID']) && is_int($_GET['uniqueID'])) {
   doSomething($_GET['uniqueID'])
}

答案很简单:)

因为电子邮件中的 url 是 /controller/action?param=val 它没有被拉入。做 /controller/action/val 和做 $fn->function($param) 是一样的 :) 希望这使得感觉