I want to send a mail automatically using cron job. Till i searched about that, there is only how to set the time and path of the file in cron folder. But i want to know about how it will run?
The execution is automatic, you need to write also the command path. for example:
30 * * * * /usr/bin/php /srv/cron/mail.php
#!/usr/bin/php at the top of your script and make the file executable:
#!/usr/bin/php <?php // . . . echo 'example'; ?>
In command line use chmod:
chmod +x mail.php
And in your crontab you can write:
30 * * * * /srv/cron/mail.php
At specific time the server will just run the script. Then you can go to /var/log to check crontab executions and you can also add error_log() to write a specific log about the excution of the functions in your script: http://php.net/manual/en/function.error-log.php
It this what you were asking for? Bye!
I have written the following code and save it in etc/cron.d/crontab.txt
2 * * * * /srv/cron/cr.php
Then i store the following php mail function in srv/cron/cr.php. Also included that smtp_confi.php and smtp_class.php in that srv/cron/cr.php
<?php include('smtp_confi.php'); include('smtp_class.php'); $to = "email@example.com"; $from = "firstname.lastname@example.org"; $subject = 'Mail send'; $body = "Automatically mail send is done"; $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body); $SMTPChat = $SMTPMail->SendMail(); ?>
Is this right way or not?
Add the command path to the crontab file or to the script, as I showed in my previous post and it will be executed.