Documentation
Email Manager
Configuration
Cygnite Framework provides you a clean and simple wrapper built on top of most popular SwiftMailer library. Mail configurations available in src/Apps/Configs/application.php file. Basic configuration is SMTP transport. You may change the configuration based on your application requirement, as like changing host, username, password, port or admin email which is globally accessible in your application.
Sending Email Using Mailer
Mailer library is a wrapper of popular swiftmailer library. Mailer library provides beautiful closure syntax and sending email is simple. You can retrieve admin email from the application configuration or set from email address as below.
use Cygnite\Helpers\Config;
$config = Config::get('global_config', 'params');
$emailDetails = array(
'subject' => "Cygnite Framework Mailer",
'from' => $config['adminEmail'],
'content' => " Hello World! " //Set your html content
);
Sending Email
Make sure you have provided swiftmailer path in src/Apps/Configs/application.php file.
use Cygnite\Common\Mail\Mailer;
Mailer::compose(function($mailer) use($emailInfo)
{
$message = $mailer->getMessageInstance()
->setSubject($emailInfo['subject'])
->setFrom($emailInfo['from'])
->setTo("sanjoy09@hotmail.com")
->setBody($emailInfo['content'], 'text/html');//'text/plain'
return $mailer->send($message);
});
Sending Email To Multiple Recipients
// Using setTo() to set all recipients in one go
$mailer->getMessageInstance()->setTo([
'person1@example.org',
'person2@otherdomain.org' => 'Person 2 Name',
'person3@example.org',
'person4@example.org' => 'Person 4 Name'
]);
You can also set recipients with setTo(), setCc() and/or setBcc().
Get total count of outgoing email
$count = Mailer::compose(function($mailer) use($emailInfo)
{
.........
return $mailer->send($message);
});
show($count);//get total count of outgoing email
Sending Email With Attachment
Add attachment with your email, addAttachment() method allow you to send email with attachment.
Mailer::compose(function($mailer) use($emailInfo)
{
.........
$mailer->addAttachment('/path/to/image.jpg');
return $mailer->send($message);
});
Inline Attachment
$mailerAttachment = $mailer->addAttachment("Your Attchment Path");
$mailerAttachment->setDisposition('inline');
Setting the Message Priority
You can also set priority of the message. Set the priority as an integer between 1 and 5 with the setPriority() method on the Message.
// Indicate "High" priority
$message->setPriority(2);
For more details read setting the Message Priority