首页 > 解决方案 > PHP Mailer,在发送电子邮件时阻止整个服务器执行

问题描述

首先,我看到了这个问题:发送邮件而不阻止“执行”

但是,我需要知道为什么 PHP 不是一个多线程进程,但如果两个人同时尝试连接就没有问题。

我实际上是通过 Ajax 调用来调用邮件脚本:

 $.ajax({
     url: 'sendMailTemplate.php', 
     type: 'POST',
     data: formData,
     processData: false,
     contentType: false,
     success: function (data) {}
...

我对 PHP 邮件程序的问题是,当我发送电子邮件时,如果这需要 10 秒,那么在 10 秒内我无法使用我网站的任何功能(并且网站对每个人来说都关闭了 10 秒)。我应该尝试使用 cron 作业吗?有没有关于 PHP 邮件程序 + cron 作业的教程?除了 cron 工作之外,最好的方法是什么?

标签: javascriptphpjquerycronphpmailer

解决方案


Should I try to use cron jobs ?
Yes

Is there any tutorial for PHP mailer + cron jobs ?
I tried my own logic by using multiple reference :

Below logic execute like queue and also sending time base on your cronjob & you hrly mailing limit.

  1. Mailing : when you click on send email that time you have store all emails into "temp_table" of your database with their "to,cc,bcc,suject,body" columns.
  2. Write cron job for hrly(your time) basic which will execute in certain time span.
  3. In cron script you have to write code which will take emails (set query limit to take no of records) from "temp_tables" & send to the recipient. After success full sending, delete those mails from "temp_table" of you database.

Whats the best way other than cron jobs ?
You have contact to your service provider to increase hrly mailing limit, increase your server speed, php.ini : change loading time (this option not works every time), refer different language like python


推荐阅读