Welcome Guest, Not a member yet? Register   Sign In
Automatic mail sending

[eluser]Roy MJ[/eluser]
I was wondering if there was any method for sending a static mail automatically. My need is that i have to send a mail for someones birthday who has registered his dob in my database. Is it possible to trigger a mail delivery automatically everyday. ??

It can be done with setting CRON jobs

[eluser]Roy MJ[/eluser]
Thankyou.. Smile

[eluser]Roy MJ[/eluser]
Ive tried doing the cron job. But i cant find a way as to how the command will be like so that i can add a cron job via cpanel.

* * * * * /usr/local/bin/php -q /home/public_html/system/application/controller/cron.php

But i dont see it working. My cron.php looks like this :

class Cron extends My_Controller {
    function cleancache(){
        * * * * * /usr/local/bin/php5 $HOME/system/scripts/clean_cache.php
        if($_SERVER['SCRIPT_FILENAME'] != 'clean_cache.php')
    function index(){
                    $to = "[email protected]";
                    $fromemail = $this->config->item('admin_email');
                    $subject = "hi";
                    $message = "heloooooooo";
                    $fromname = "Aroma";
                    mail($to, $subject, $message, "From: $fromname<$fromemail>" );


Can u please find what im doing wrong here. In cpanel i gave this command as cron job..


I suggest you use plain php to run your cron jobs rather than using CI. Also, why this statement is in constructor?
* * * * * /usr/local/bin/php5 $HOME/system/scripts/clean_cache.php

Following links will help you

Cron wiki

cron bootstrapper


[eluser]Roy MJ[/eluser]

[eluser]Roy MJ[/eluser]
* * * * * /usr/local/bin/php5 $HOME/system/scripts/clean_cache.php

When i googled i came across a page where it said the above line is the cron command.

I used the below step too. But none of it is triggering the automatic mail sending.
* * * * * /usr/local/bin/php5 $HOME/system/application/controller/cron.php

Have you implemented the cron job anywhere??.

[eluser]Roy MJ[/eluser]
I did it in controller as eventually im planning to do mailing to emails selected from database. So first i was trying to get it working by static contents and static emails. I have found a Cron job application inside the cpanel in the advanced section. In that also we need to give a cron command. The command is what i had mentioned above. But its not working either. If you have done the mail sending, can you please tell me whats wrong with my code. I cant do it in simple php as it would mean i cant access the database.

I usually store my cron files in cron folders. You can also user the db config from system/application/database.php and config values from system/application/config.php in that file. Here is how I do it. Suppose there is a file email_cron.php
define( 'BASEPATH', dirname(__FILE__) );

include( BASEPATH  .'/../system/application/config/database.php' );
include( BASEPATH  .'/../system/application/config/config.php' );

This will include mentioned files, so you can access database settings, base_url etc. Below goes the email code you want to run
//select email query, mail code , etc....

You can set through cpanel when this cron will run, and the command will be path to this cron file. For sending mail, you can also use phpmailer.

Theme © iAndrew 2016 - Forum software by © MyBB