Below code is provided, it sends file as an attachment, but file is empty i.e file does not have any data. Only I can see file name in email as an attachment, file have data which is saved, but in email it is empty.
$basePath = Yii::app()->basePath;
Data come from database table and here .xls file is created and saved in local folder
file_put_contents($basePath.'/../reports/excelreport.xls', $data);
$htmlbody = 'Content goes here';
Saved file path, which to send in email as an attachment.
$path = Yii::app()->basePath . '/../reports/excelreport.xls';
$message = Yii::app()->sendgrid->createEmail();
$message->setHtml($htmlbody)
->setSubject('Reports Alert')
->addTo($email)
->setFrom('account@simplifyvms.net')
->setAttachment($path);
Yii::app()->sendgrid->send($message);
?>