V
V
vladislav9972020-09-18 10:48:33
PHP
vladislav997, 2020-09-18 10:48:33

Why does cron accept a simple PHP script, but not a little more complicated one?

Tell me why cron perceives a simple PHP script, but a little more complicated - no?

crontab -e:

* * * * * php /var/www/project/includes/mail/cron.php


Accepts and works:
$to = '...';
    $subject = 'Its test msg';
    $message = 'Cron. You login: ';
    $from = "From: [email protected]\r\n"
        ."Content-type: text/html; charset=utf-8\r\n"
        ."X-Mailer: PHP mail script";

    mail(
        $to,
        $subject,
        $message,
        $from
    );


It does not perceive, but if you go through a direct link - it works:
require '../model.php';
$allUsers = R::findAll('users');

foreach ($allUsers as $user)
{
    $to = $user->login;
    $subject = 'Its test msg';
    $message = 'Cron. You login: '.$user->login.' ';
    $from = "From: [email protected]\r\n"
        ."Content-type: text/html; charset=utf-8\r\n"
        ."X-Mailer: PHP mail script";

    mail(
        $to,
        $subject,
        $message,
        $from
    );
}


upd. Logs in the script:
5f64688006f42181944200.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-09-18
@vladislav997

Read the logs. For example, there are no users in the database. Or there are too many of them and there is not enough memory. Execute your script yourself through the console, turning on error output. The problem is in the script, not in the cron.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question