douzi8112 2013-11-13 10:51
浏览 6

从主PHP线程发送电子邮件

In my wesbite, when a user submit a form, I need to update my DB and send several e-mails (to him, to admin, ...)

For now, I'm doing in inside the target page of the form.php (which in my case is also form.php). The problem is that sending e-mails takes a while. And from the user point of view, it just seems that the page takes a while to load.

Is there a way that the e-mails will be done on a separate "thread" so that I the user doesn't have to wait the emails to be sent?

  • 写回答

1条回答 默认 最新

  • douheng8629 2013-11-13 11:09
    关注

    You can use jquery ajax to this. Simply send the necessary information that needs to be stored to a backend php file and have the emailing code in that file. It will have the emails sent to you behind the curtain.

    $.ajax({
      type: "POST",
      url: backend.php,
      data: data,
      success: success,
      dataType: dataType
    });
    

    Have your backend file do the needful saving and emailing. Also, you can use a queue worker system, but I don't how effective it would be to you. Depends on the complexity and size of the app IMHO.

    评论

报告相同问题?