axel axel
axel axel

Reputation: 253

PHP Mailer, blocking whole server execution while sending an e-mail

First, I've seen this question: Send mail without blocking 'execution'

But, I need to know why PHP is not a multi-threading process but has no problem if two people try to connect at the same time.

I am calling the mail script by an Ajax call actually :

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

My problem with PHP mailer is that, when I'm sending an email if this takes 10 seconds, then for 10 seconds i can't use any feature of my website ( and the website is like down for everyone for 10 seconds). Should I try to use cron jobs? Is there any tutorial for PHP mailer + cron jobs? What's the best way other than cron jobs?

Upvotes: 1

Views: 674

Answers (2)

Ashu
Ashu

Reputation: 1320

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

Upvotes: 1

Just switch to a smtpd that allow placing mails in queue and sending them asynchronously.

Upvotes: 0

Related Questions