- Notifications
You must be signed in to change notification settings - Fork0
Elastic Email plugin for CakePHP 3
License
sprintcube/cakephp-elastic-email
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This plugin provides email delivery usingElastic Email.
This plugin has the following requirements:
- CakePHP 3.4.0 or greater.
- PHP 5.6 or greater.
You can install this plugin into your CakePHP application usingcomposer.
composer require sprintcube/cakephp-elastic-emailAfter installation,Load the plugin
Plugin::load('ElasticEmail');
Or, you can load the plugin using the shell command
$ bin/cake plugin load ElasticEmail
Set your Elastic Email Api key inEmailTransport settings in app.php
'EmailTransport' => [...'elasticemail' => ['className' =>'ElasticEmail.ElasticEmail','apiKey' =>'your-api-key'// your api key ]]
If you face an SSL certificate error, please follow below steps:
- Openhttp://curl.haxx.se/ca/cacert.pem
- Copy the entire page and save it as a "cacert.pem"
- Open your php.ini file and insert or update the following line: curl.cainfo = "[pathtofile]\cacert.pem"
And create new delivery profile inEmail settings.
'Email' => ['default' => ['transport' =>'default','from' =>'you@localhost',//'charset' => 'utf-8',//'headerCharset' => 'utf-8', ],'elasticemail' => ['transport' =>'elasticemail' ]]
You can now simply use the CakePHPEmail to send an email via Elastic Email.
$email =newEmail('elasticemail');$email->setFrom(['you@yourdomain.com' =>'CakePHP Elastic Email']) ->setSender('someone@example.com','Someone') ->setTo('foo@example.com.com') ->addTo('bar@example.com') ->setHeaders(['X-Custom' =>'headervalue']) ->setSubject('Email from CakePHP Elastic Email plugin') ->send('Message from CakePHP Elastic Email plugin');
That is it.
You can also use few more options to send email via Elastic Email APIs. To do so, get the transport instance and call the appropriate methods before sending the email.
You can mark the email astransactional email.
$email =newEmail('elasticemail');$emailInstance =$email->getTransport();$emailInstance->isTransactional(true);$email->send();
You can pass your own headers. It must be prefixed with "X-". Use the defaultEmail::setHeaders method like,
$email =newEmail('elasticemail');$email->setFrom(['you@yourdomain.com' =>'CakePHP Elastic Email']) ->setSender('someone@example.com','Someone') ->setTo('foo@example.com.com') ->addTo('bar@example.com') ->setHeaders(['X-Custom' =>'headervalue','X-MyHeader' =>'myvalue' ]) ->setSubject('Email from CakePHP Elastic Email plugin') ->send('Message from CakePHP Elastic Email plugin');
Make sure you have enabled custom header from your Elastic Email settings.
Set your attachments usingEmail::setAttachments method.
$email =newEmail('elasticemail');$email->setFrom(['you@yourdomain.com' =>'CakePHP Elastic Email']) ->setSender('someone@example.com','Someone') ->setTo('foo@example.com.com') ->addTo('bar@example.com') ->setAttachments(['cake_icon1.png' => Configure::read('App.imageBaseUrl') .'cake.icon.png','cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') .'cake.icon.png'],WWW_ROOT .'favicon.ico' ]) ->setSubject('Email from CakePHP Elastic Email plugin') ->send('Message from CakePHP Elastic Email plugin');
You need to have some credit in your account to send attachments. Otherwise you will get
Not enough credit for campaign.error.
You can use the template created in Elastic Email backend. Get the template id by either using their API or from the URL.Set the template id usingsetTemplate method.
$email =newEmail('elasticemail');$emailInstance =$email->getTransport();$emailInstance->setTemplte(123);$email->send();
Elastic Email provides a nice way to replace the template content using template variables. You can use variables like {firstname}, {lastname} in your template and pass their replacement value.
$mergeVars = ['firstname' =>'Foo','lastname' =>'Bar','title' =>'Good Title'];$email =newEmail('elasticemail');$emailInstance =$email->getTransport();$emailInstance->setMergeVariables($mergeVars);$email->setFrom(['from@example.com' =>'CakePHP Elastic Email']) ->setTo('to@example.com') ->setEmailFormat('both') ->setSubject('{title} - Email from CakePHP Elastic Email plugin') ->send('Hello {firstname} {lastname}, <br> This is an email from CakePHP Elastic Email plugin.');
You can schedule the email to be sent in future date. You can set upto 1 year in future i.e. 524160 minutes.
$email =newEmail('elasticemail');$emailInstance =$email->getTransport();$emailInstance->setScheduleTime(60);// after 1 hour from sending time$email->send();
If you have a problem with this plugin or any bug, please open an issue onGitHub.
About
Elastic Email plugin for CakePHP 3
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.