Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/ivantcholakov/codeigniter-phpmailer

A CodeIgniter 3 compatible email-library powered by PHPMailer
https://github.com/ivantcholakov/codeigniter-phpmailer

codeigniter php phpmailer

Last synced: about 1 month ago
JSON representation

A CodeIgniter 3 compatible email-library powered by PHPMailer

Lists

README

        

[![Latest Stable Version](https://poser.pugx.org/ivantcholakov/codeigniter-phpmailer/v)](//packagist.org/packages/ivantcholakov/codeigniter-phpmailer)
[![Total Downloads](https://poser.pugx.org/ivantcholakov/codeigniter-phpmailer/downloads)](//packagist.org/packages/ivantcholakov/codeigniter-phpmailer)
[![Latest Unstable Version](https://poser.pugx.org/ivantcholakov/codeigniter-phpmailer/v/unstable)](//packagist.org/packages/ivantcholakov/codeigniter-phpmailer)
[![License](https://poser.pugx.org/ivantcholakov/codeigniter-phpmailer/license)](//packagist.org/packages/ivantcholakov/codeigniter-phpmailer)

A CodeIgniter compatible email-library powered by PHPMailer
===========================================================

Version: 1.5.0
Author: Ivan Tcholakov , 2012-2022.
License: The MIT License (MIT), http://opensource.org/licenses/MIT

This library is compatible with CodeIgniter 3.1.x and PHP >= 7.3.0.

Tested on CodeIgniter 3.1.13 (March 3rd, 2022) and PHPMailer Version 6.6.4 (August 22nd, 2022).

Links
-----

Package: https://packagist.org/packages/ivantcholakov/codeigniter-phpmailer

PHPMailer: https://github.com/PHPMailer/PHPMailer

Installation
------------

Enable Composer to be used by CodeIgniter. Check this page from its documentation:
https://www.codeigniter.com/userguide3/general/autoloader.html .
You need to see or decide when your vendor/ directory is (to be) and within the
CodeIgniter's configuration file application/config/config.php you need to set the
configuration option $config['composer_autoload'] accordingly. For the typical location
application/vendor/ the configuration setting would look like this:

```php
$config['composer_autoload'] = APPPATH.'vendor/autoload.php';
```

Within application/config/constants.php add the following lines:

```php
// Path to Composer's vendor/ directory, it should end with a trailing slash.
defined('VENDORPATH') OR define('VENDORPATH', rtrim(str_replace('\\', '/', realpath(dirname(APPPATH.'vendor/autoload.php'))), '/').'/');
```

It is assumed that Composer's vendor/ directory is placed under CodeIgniter's
application/ directory. Otherwise correct the setting so VENDORPATH to point correctly.

If PHPMailer was previously installed through Composer, uninstall it temporarily:

```
composer remove PHPMailer/PHPMailer
```

Now install this library's package, it will install a correct version of PHPMailer too:

```
composer require ivantcholakov/codeigniter-phpmailer
```

Create a file application/helpers/MY_email_helper.php with the following content:

```php
load->library('email');

$subject = 'This is a test';
$message = '

This message has been sent for testing purposes.



';

// Get full html:
$body = '


' . html_escape($subject) . '

body {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 16px;
}

' . $message . '

';
// Also, for getting full html you may use the following internal method:
//$body = $this->email->full_html($subject, $message);

// Attaching the logo first.
$file_logo = FCPATH.'apple-touch-icon-precomposed.png'; // Change the path accordingly.
// The last additional parameter is set to true in order
// the image (logo) to appear inline, within the message text:
$this->email->attach($file_logo, 'inline', null, '', true);
$cid_logo = $this->email->get_attachment_cid($file_logo);
$body = str_replace('cid:logo_src', 'cid:'.$cid_logo, $body);
// End attaching the logo.

$result = $this->email
->from('[email protected]')
->reply_to('[email protected]') // Optional, an account where a human being reads.
->to('[email protected]')
->subject($subject)
->message($body)
->send();

var_dump($result);
echo '
';
echo $this->email->print_debugger();

exit;
```

Load the corresponding page, executte this code. Check whether an email has been sent. Read the error message,
if any, and make corrections in your settings.

Note, that most of the SMTP servers require "from" address of the message to be the same as the address within
$config['smtp_user'] setting.

At the end remove this test.

The API of this library is the same as the original Email API. Read the CodeIgniter's manual about
[Email Class](https://www.codeigniter.com/userguide3/libraries/email.html).

For supporting CodeIgniter 2.x and CodeIgniter 3.0.x a manual installation of an older version of this
library is needed, see https://github.com/ivantcholakov/codeigniter-phpmailer/tree/1.3-stable