I used below code for sendGrid codes for sending mails from my project.
require_once(YII_BASE_PATH . "/lib/sendgrid-php/SendGrid.php");
require_once(YII_BASE_PATH . "/lib/sendgrid-php/SendGrid_loader.php");
$sendgrid = new SendGrid('uname', 'pwd');
$mail = new SendGrid\Mail();
$mail->addTo('xxxxxxxxxx@gmail.com')->
setFrom('xxxyyyy5@yahoo.co.in')->
setSubject('Subject goes here')->
setText('Hello World!')->
setHtml('<strong>Hello World!</strong>');
$sendgrid->smtp->send($mail);
I already downloaded the sendGrid package and put it into lib folder in yii.
if I execute the above code i got error like "include(Swift_DependencyContainer.php): failed to open stream: No such file or directory"
if I included the above file i got error like another file need to be include.
Kindly advice on this.
Here is what works for me:
finally i make it works. for your reference i list down the steps (for myself also),
1) we need to download the sendgrid-php pack from https://github.com/sendgrid/sendgrid-php/downloads
2) Unzip the folder and placed in your project folder like " app/mail/".
3) the create one .php file for mail for mail sending in that folder like " app/mail/mail.php ".
4)in that file,
5) i need to send mail when i redirect to mailsend page. so i write code in controller file in Actionmailsend(),
just redirection. that's it. mail send successfully.
here AT::getUrl() - used for get baseurl.
it's not integrated to yii. we used mail functionality by to place the sendGrid package folder into inside the yii project folder and used it.
It seems that SendGrid relies on include path to load its dependencies. So you must use one or several
statements to add SendGrid to the include path. Maybe :
See : http://www.yiiframework.com/doc/api/1.1/YiiBase#import-detail
I use Zend_Mail instead of SendGrid, but I had the same kind of include path problem. I've solved it by using these statements :
I think the solution to your problem is similar.