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
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.
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.
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”