Executing php file to send mail

Hello.

I need to send a custom made email using corn job. Manual activation of the file is ok and the mail is sent. Question is, how to set the cronjob in Dolibarr?

I have set Shell command and tried 2 things:

First: set “/opt/cpanel/ea-php73/root/usr/bin/php” as Command and “/home/myname/public_html/dolibarr/path_to_file/daily.stats.php” as comment

Second: Set everything in “Command”

Then I try https://URL/public/cron/cron_run_jobs.php?securitykey=SECURITY_KEY&userlogin=USERNAME&id=cronjobid and the for each option the result is “cron_run_jobs.php cronjobid: 6 priority=0 entity=1 label=TASK_LABEL - qualified - result of run_jobs = 1 - reprogrammed Result: 1 jobs - 1 launched = 1 OK + 0 KO” but e-mail is not send.

I’ve also tried to set a corn job in the Cpanel, using the same command, but again no result (I presume this is because Dolibarr needs user authentication).

Any help appreciated.

P.S.: I am using phpmailer for composing and sending the mail.

Hi

Can you check configuration and test mail in your Setup > Emails > Emails Setup

Tweak php.ini in case of any requirements.

If mails go from ERP, then I guess your config in Admin Tools > Scheduled Jobs must work.

thanks
yesbee

Hello.

yes, test emails are working. Direct access to the .php file via URL also. The problem is with the cronjobs. The return (in most cases) is the login screen for Dolibarr.

Hi @milenmk,

Did you find a way around this?
How do we run a php page without login when set to use with cron?

You can set in the beginning the following options:

if (!defined('NOLOGIN')) {
    define("NOLOGIN", 1); // This means this output page does not require to be logged.
}
if (!defined('NOCSRFCHECK')) {
    define("NOCSRFCHECK", 1); // We accept to go on this page from external website.
}
if (!defined('NOIPCHECK')) {
    define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}
if (!defined('NOBROWSERNOTIF')) {
    define('NOBROWSERNOTIF', '1');
}
if (!defined('NOIPCHECK')) {
    define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
}

and then, for the cronjob use “Job type >> Shell command” and as a command put “curl https://url_to_file”.

However, note that this will open this page for public access i.e. anybody can open it and trigger the script in it.

As for the general cron execution, there was a problem on the hosting side with the path to the php executable.

Also, you should amend the file “cron_run_jobs.php” in “Scripts >>> Cron” folder to point to the actual location of “master.inc.php” if Dolibarr main folder is not under the same main folder with “Scripts” or you have changed the name of the htdocs folder to something else. The setting is on line 45 require_once $path."../../htdocs/master.inc.php";

To everyone who is trying to achieve something like this.
Do what @milenmk said in the above & then also add an .htaccess file in the folder.
Basically the .htaccess file is to restrict only a specific IP to run the script, other IPs should not be able to access the page.

The .htaccess file should look something like this:

order deny,allow
deny from all
allow from “Your IP”

Hope this helps.