CodeIgniter Forums
Automatic mail sending - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Automatic mail sending (/thread-37507.html)

Pages: 1 2


Automatic mail sending - El Forum - 01-12-2011

[eluser]Roy MJ[/eluser]
Hi,
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. ??



Automatic mail sending - El Forum - 01-12-2011

[eluser]Atharva[/eluser]
It can be done with setting CRON jobs


Automatic mail sending - El Forum - 01-12-2011

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


Automatic mail sending - El Forum - 01-14-2011

[eluser]Roy MJ[/eluser]
Hey,
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 :

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

?&gt;

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

Code:
$HOME/system/application/controller/cron.php



Automatic mail sending - El Forum - 01-14-2011

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



Automatic mail sending - El Forum - 01-14-2011

[eluser]Atharva[/eluser]
Following links will help you


Cron wiki

cron bootstrapper

cron


Automatic mail sending - El Forum - 01-14-2011

[eluser]Roy MJ[/eluser]
thankyou..


Automatic mail sending - El Forum - 01-14-2011

[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??.


Automatic mail sending - El Forum - 01-14-2011

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


Automatic mail sending - El Forum - 01-14-2011

[eluser]Atharva[/eluser]
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
Code:
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
Code:
//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.