1. Go to this page and download the library: Download hydreflab/laravel-mailer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hydreflab / laravel-mailer example snippets
'from' => ['address' => null, 'name' => null],
interface MailerInterface
{
/**
* @param string $email
* @return void
*/
public function setFromEmail($email);
/**
* @param string $name
* @return void
*/
public function setFromName($name);
/**
* @param string $subject
* @return void
*/
public function setSubject($subject);
/**
* @param string $template
* @return void
*/
public function setTemplate($template);
/**
* @param string|null $subject
* @param string|null $template
* @return bool
*/
public function send($subject = null, $template = null);
/**
* @param string $queue
* @param string|null $subject
* @param string|null $template
* @return bool
*/
public function queue($queue, $subject = null, $template = null);
/**
* @param Recipient $recipient
* @return void
*/
public function addRecipient(Recipient $recipient);
/**
* @param Header $header
* @return void
*/
public function addHeader(Header $header);
/**
* @param string $email
* @return void
*/
public function setReplyTo($email);
/**
* @param Variable $variable
* @return void
*/
public function addGlobalVariable(Variable $variable);
/**
* @param Recipient $recipient
* @param Variable $variable
* @return void
*/
public function addLocalVariable(Recipient $recipient, Variable $variable);
/**
* @param Attachment $attachment
* @return void
*/
public function addAttachment(Attachment $attachment);
/**
* @return array
*/
public function getData();
/**
* @param array $data
* @return void
*/
public function setData(array $data);
}
class Notifier
{
protected $mailer;
public function __construct(\DeSmart\Mailer\MailerInterface $mailer)
{
$this->mailer = $mailer;
}
public function notify()
{
// If you want to override default sender email and name
$this->mailer->setFromEmail('[email protected]');
$this->mailer->setFromName('John Doe');
// You can set subject and template identifier
$this->mailer->setSubject('Test subject');
$this->mailer->setTemplate('test-template');
// To add recipient
$this->mailer->addRecipient(new Recipient('Jane Doe', '[email protected]'));
// or
$this->mailer->addRecipient(new Recipient('Jane Doe', '[email protected]'), RecipientType::to());
// To add BCC recipient
$this->mailer->addRecipient(new Recipient('Jane Doe', '[email protected]', RecipientType::bcc()));
// To add CC recipient
$this->mailer->addRecipient(new Recipient('Jane Doe', '[email protected]'), RecipientType::cc());
// To add global variable (shared between all recipients)
$this->mailer->addGlobalVariable(new Variable('variable_name', 'variable_value');
// To add local variable (for specified recipient)
$this->mailer->addLocalVariable(
new Recipient('John Doe', '[email protected]'),
new Variable('variable_name', 'variable_value')
);
// To add attachment
$this->mailer->addAttachment(new Attachment('application/pdf', 'attachment.pdf', 'PDF content in plain text'));
$this->mailer->addAttachment(new Attachment('text/html', 'attachment.txt', 'Txt file content in plain text'));
// To set reply to
$this->mailer->setReplyTo('[email protected]');
// or (Mandrill only)
$this->mailer->addHeader(new Header('Reply-To', '[email protected]')
// To send email
$this->mailer->send();
// or to send email if subject and/or template was not set before
$this->mailer->send('Test subject', 'test-template');
// To add email to queue
$this->mailer->queue();
// or to add email to defined queue
$this->mailer->queue('queue_name');
// or to add email to queue if subject and/or template was not set before
$this->mailer->queue('queue_name', 'Test subject', 'test-template');
}
}