AnsweredAssumed Answered

How to send emails using cron?

Question asked by Sohan Tirpude on Nov 20, 2014
Hello everyone, I am using SugarCRM 6.5.x community edition. I want send emails using cron. I have no idea how to send emails using cron, so I am postind here my code ...please take a look and let me know if it is correct and if it is then please let me know what to do next. Thank you.


    require_once('include/SugarPHPMailer.php');
           
    $query = "SELECT id_c FROM sohan_passwor_management_cstm WHERE ABS(DATEDIFF(NOW(), user_register_datetime_c)) >= 80 AND ABS(DATEDIFF(NOW(), user_register_datetime_c)) < 90)";
    $result = $bean->db->query($query, true);
    while($user_id = $bean->db->fetchByAssoc($result)){
               
        $user=BeanFactory::getBean('Users',$user_id['id_c']]);
        $primary_email=$user->emailAddress->getPrimaryAddress($user);
        $emailObj = new Email();
        $defaults = $emailObj->getSystemDefaultEmail();
        $email = new SugarPHPMailer();
        $mail->setMailerForSystem();
        $mail->From = $defaults['email'];
        $mail->FromName = $defaults['name'];
        $mail->Subject="Regarding changing your password."
        $mail->Body="Hello this is testing ....!";
        $mail->prepForOutbound();
        $mail->AddAddress= $primary_email;
        @$mail->Send();
    }               
?>

Also please let me know, if there is any other way to make it simple. Thank you

Outcomes