Codeigniter: Install Swift Mailer using Composer

Created at: March 11, 2014; Last update: March 12, 2014

Composer is the new kid on the block. Composer is a tool used to distribute and manage packages. I first heard of it while taking a look at Laravel. Composer’s power consists in the fact that the packages distributed by it are framework agnostic.

From the start I will assume that you have composer installed. Now, going to packagist.org, look for swiftmailer (https://packagist.org/packages/swiftmailer/swiftmailer). As you can see the json command for getting the latest distribution of swiftmailer is: “required”: “swiftmailer/swiftmailer”: “5.1.*@dev”.

So, we will have to make a composer.json file inside the folder that contains the system and application folders, containing the following lines:

After we do this, using the command prompt, we go to the folder that contains the composer.json and there we write the command composer install, which will start the installation of swiftmailer.

As you will see, after the installation, a new folder will appear, named vendor, and inside it we will find swiftmailer.

Once we have the swiftmailer installed we can use it inside the codeigniter application.

So, let’s make a controller and name it Swiftmailer.php

Now, if you will visit the controller and all went well, a mail will be sent and a confirmation of the sending will be displayed on the browser.

Worth reading:

Using Swift Mailer with CodeIgniter

Swift Mailer and Codeigniter

Swiftmailer documentation

3 thoughts on “Codeigniter: Install Swift Mailer using Composer

  1. sandeepm

    Thanks,
    But i am using thease two lines
    $transport = Swift_SmtpTransport::newInstance(‘smtp.gmail.com’, 465,’ssl’)
    ->setUsername(‘***@gmail.com’)
    ->setPassword(‘******’);
    many times in application in mvc, where i am to place and how to call thease functions

    Reply
  2. Power Hyper Programmer

    “So, we will have to make a composer.json file inside the folder that contains the system and application folders, containing the following lines:”

    Please be more specific with the respective folders. The composer.json file is supposed to be created in the web development project you’re working on:
    C:\wamp\www…

    Reply
    1. avenirer Post author

      Well… I guess there is only one system and one application directory in CodeIgniter. And most of the time they are in the same directory. I really can’t be more specific, considering the server can be installed inside any partition and directory…

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.