将表单发送到用户永远不知道或看到的 php 脚本

发布于 2024-12-29 19:23:31 字数 442 浏览 0 评论 0原文

在我的网站上,我有一个功能可以让您跟踪其他用户的更新。当用户更改其信息时,关注他或她的任何人都将收到有关此更改的电子邮件。

我进行了设置,以便 php 更改数据库中的信息,然后搜索用户联系人以查看谁关注他/她,并向关注的人发送电子邮件,通知他们更改。

自从添加此通知功能以来,我遇到的问题是,除了页面加载(表单帖子本身)并几乎立即显示更改(取决于有多少人关注特定用户)之外,它可能需要一些时间用于加载页面并显示更新(因为 php 在页面重新加载之前发送所有电子邮件)。

我该如何设置它,发送电子邮件的脚本在后台某处运行,并且用户不必在页面重新加载之前等待电子邮件发送,甚至可能退出网站并如果脚本仍在运行,仍然会发送电子邮件吗?

PS 我所有的编程和开发技能都是自学的,所以我不知道很多术语......你可能需要简化你的回答,这样我才能理解你在说什么。对于给您带来的不便,我们深表歉意,并非常感谢您的帮助。

On my site, I have a feature that allows you to follow the updates of other users. When a user makes a change to their info, anyone following him or her will be emailed of this change.

I have it set up so that the php changes the info in the database, then searches through the users contacts to see who is following him/her, and sends emails to those who are following notifying them of the change.

The problem I have run into since adding this notification feature, is that insead of the page loading (form posts to itself) and showing the change almost instantly, (depending on how many people are following a particular user) it can take a few munites for the page to load and show the update (because the php is sending all the emails before the page reloads).

How can I set it up, where the script to send the emails, is run somewhere in the background, and the user does not have to wait for the emails to send before the page reloads, and could possibly even exit out of the website and still have the emails send if still the script is still running?

P.S. All my programming and development skills have been self taught, so I don't know a lot of terminology..... You may have to dumb down your responses so that I will understand what you are talking about. Sorry for the inconvenience, and thank you very much for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2025-01-05 19:23:31

我很惊讶仅仅发送一些电子邮件就需要几分钟的时间,但无论如何,您至少可以通过四种方式来做到这一点:

  • 使用 ajax 将表单数据发送到一个单独的脚本,该脚本在表单正常发布时发送电子邮件
  • 有表单脚本fork(需要 pcntl
  • 通过 php 向您自己的页面发出异步请求(使用 cURL 设置较低的超时,或打开套接字)
  • 使用 exec('script-that-sends-emails args >> 其他文件 2>&1 &');

I'm surprised it takes several minutes just to send some emails, but anyway you can do this in at least four ways:

  • Use ajax to send the form data to a separate script that sends the emails while the form posts normally
  • Have the form script fork (pcntl required)
  • Make an asynchronous request to your own page via php (either set a low timeout with cURL, or open a socket)
  • Use exec('script-that-sends-emails args >> some-other-file 2>&1 &');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文