简体   繁体   中英

How to reload automatically with PHPmailer and cron jobs Cpanel

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM