0

I will create an automated notification with PHPmailer Codeigniter and cron jobs cpanel in order to execute today's deadline data sent by email from the database.

This is my path : mydomain.com/email/send

class Email extends CI_Controller{
    function __construct(){
        parent::__construct();

        $this->load->model('dataemail');
        $this->load->library('MyPHPMailer'); // load library
    }

    function send(){
        $data = $this->dataemail->model_email()->result(); 

        foreach ($data as $d):
            $mail = new PHPMailer();
            $mail->isSMTP();
            $mail->Host = "smtp.gmail.com";
            $mail->SMTPSecure = "ssl";
            $mail->Port = 465;
            $mail->SMTPAuth = true;
            $mail->Username = 'our@gmail.com';
            $mail->Password = 'xxxxxxx';

            $mail->setFrom('our@gmail.com', 'Our Name');
            $mail->addAddress('you@gmail.com', 'Your Name');
            $recipients = $this->dataemail->user()->result();
                foreach($recipients as $e)
                {
                   $mail->AddCC($e->email, $e->email);
                }
            $mail->Subject = $d->content_notification;
            if ($mail->send()) {
                echo "Email send!";
            } else {
                echo "Email failed";
            }
        endforeach;
    }
}

when I access mydomain.com/email/send or refresh this link, then the data will automatically send a message to my email. this can be done.

I use the cron jobs service to reload every two times a day. Then, what commands should I write in the Cron Jobs Cpanel setting?

I have tried this command but it does not work

0 0.12 * * * / usr / local / bin / php -q /home/user/mydomain.com/email/send > / dev / null 2> & 1

So, help me to write the correct command so that this page can reload automatically every day and deadline data can go into my email. thanks.

1 Answers1

0

The cron command would be :

0 0,12 * * * /usr/local/bin/php -q /home/user/mydomain.com/email/send.php > /dev/null 2>&1

The hours are separated by comma. Just make sure both the php executable path and the send.php file path are correct. Cheers.

Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26