Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:58:35+00:00 2026-06-13T18:58:35+00:00

I am trying to send mail with SendGrid in yii php framework. Here is

  • 0

I am trying to send mail with SendGrid in yii php framework.

Here is my action 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 error:

Use of undefined constant ROOT_DIR – assumed ‘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 issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:58:37+00:00Added an answer on June 13, 2026 at 6:58 pm

    Got it:

        public function actionSendmail()
        {
            define('ROOT_DIR', Yii::app()->basePath . '/lib/sendgrid-php/');
            define('SWIFT_REQUIRED_LOADED', true);
            Yii::import('application.lib.sendgrid-php.SendGrid');
            Yii::import('application.lib.sendgrid-php.lib.swift.classes.Swift', true);
            Yii::registerAutoloader(array('Swift', 'autoload'));
            Yii::import('application.lib.sendgrid-php.lib.swift.swift_init', true);
            Yii::setPathOfAlias('SendGrid', Yii::app()->basePath . '/lib/sendgrid-php/SendGrid/');
    
            $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');
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send mail using phpMailer. It's my code: <?php require_once('phpmailer/class.phpmailer.php'); $mail =
I'm trying to send mail via the PHP mail() function which as far as
I`m trying to send e-mail via c# and use the following code: public static
I am trying to send mail in PHP . I use same code for
I'm having an error trying to send mail with PHP using the mail() function.
I'm trying to send a mail using Zend_Mail using the following code: function sendMail()
I am trying to send mail using SmtpClient() within my Winforms VB.Net program Here
I am trying to send mail from localhost using PHP. I am using the
I am trying to send a mail from a from in PHP, it's not
I am trying to send email using mail() in php. I need the message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.