How to get current server avaible quota to send emails with PHP

45
March 14, 2019, at 11:30 PM

im in a development of an website that needs to send massive emails to their users. I have done the PHP script to send emails using PHPMailer and its ok, but the server has a limit by hour to send emails.

I want to know if there's any way to query the current avaible quota to send emails so i can iterate using a for/while/etc and never get the error of mail not send (and get the error though email too).

In this moment im doing something like this:

While(...)
{
    if(cont < 200)
    {
         $mail = new PHPMailer(true);
         try
         {
             // send email to current user using PHP mailer
             // and update database to not send him another email until next month.
         }
         catch(Exception $e)
         {
             echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
         }
    }
    else
    {
        // Limit reached, dont send more emails.
        break;
    }
    cont++;
}

But if I send emails though another scripts (new users, notifications, etc) my quota avaible will be != from my server limit, so this scripts will always send me the error email. I will like to do something like this:

$limit_quota = getQuota();
while(...)
{
    if(cont<limit_quota)
    {
        // send emails.. (same code)
    }
    else
    {
        // Limit reached, dont send more emails.
        break;
    }
    cont++;
}

Note: Im using CRON to shedule this php script every month.

READ ALSO
.htaccess file is not working properly on Godaddy server

.htaccess file is not working properly on Godaddy server

I have hosted my folder on godaddy linux cpanelWordpress files are in inside /public_html/tma

52
How to make dynamic url with multiple vars like in Laravel?

How to make dynamic url with multiple vars like in Laravel?

How to make dynamic url with multiple vars like in Laravel in my own small MVC? Like when I write Route::get('/post/$1/$2', 'PostsController@showUserPosts')How do you approach this?

48
Yii2 - cannot add foreign key constraint

Yii2 - cannot add foreign key constraint

I am coming from the Laravel worldI know that foreign keys are necessary for relations to work correctly

23
PHP command in Bash does not execute code

PHP command in Bash does not execute code

Ok, so I have a problem with this thing I found on a MacBook AirIt's called terminal and you can do crazy stuff on it

58