I am trying to send mail using SendGrid in yii php framework.
Here is my code to send mail:
public function actionSendmail() { Yii::setPathOfAlias('Libs', Yii::app()->basePath.'/lib'); Yii::setPathOfAlias('SendGrid', Yii::app()->basePath.'/lib/sendgrid-php/SendGrid'); Yii::import('SendGrid.*'); Yii::import('Libs.sendgrid-php.SendGrid', true); $sendgrid = new SendGrid('uname', 'pwd'); $mail = new SendGrid\Mail(); $mail->addTo('to-email')-> setFrom('from-email')-> setSubject('Subject goes here')-> setText('Hello World!')-> setHtml('<strong>Hello World!</strong>'); $sendgrid->smtp->send($mail); $this->render('mail'); }
which shows the error:
Using undefined constants ROOT_DIR - assumed to be 'ROOT_DIR'
/var/www/apsiap/protected/lib/sendgrid-php/SendGrid/Smtp.php(18)
06 { 07 //the available ports 08 const TLS = 587; 09 const TLS_ALTERNATIVE = 25; 10 const SSL = 465; 11 12 //the list of port instances, to be recycled 13 private $swift_instances = array(); 14 protected $port; 15 16 public function __construct($username, $password) 17 { 18 require_once ROOT_DIR . 'lib/swift/swift_required.php'; 19 call_user_func_array("parent::__construct", func_get_args()); 20 21 //set the default port 22 $this->port = Smtp::TLS; 23 } 24 25 /* setPort 26 * set the SMTP outgoing port number 27 * @param Int $port - the port number to use 28 * @return the SMTP object 29 */ 30 public function setPort($port)
How to solve this problem?
source share