PHP code example of alvlapo / phalcon-mailer

1. Go to this page and download the library: Download alvlapo/phalcon-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/ */

    

alvlapo / phalcon-mailer example snippets


$transport = new \Swift_SendmailTransport();
$view = \Phalcon\Di::getDefault()->getShared('view');

$mailer = new \Rotoscoping\Phalcon\Manager($transport, $view);

// Add mailer to container (optional)
\Phalcon\Di::getDefault()->setShared('mailer', $mailer);

// Get mailer from DI
$mailer = \Phalcon\Di::getDefault()->get('mailer');

// Compose mail
$mailer
  ->to('[email protected]')
  ->subject('Simple subject')
  ->text('Simple text part message')
  ->send();
  
// Fin

// You must initialize and add Manager instance to DI as 'mailer' service (see above)
// or extend Mail class and owerride method getMailerInstance()

$mail = new Mail();
$mail
  ->from('[email protected]', 'Support team')
  ->to('[email protected]')
  ->subject('Simple subject')
  ->text('Simple text part message');
  
$mail->send();

$defaultMail = new Mail();
$defaultMail
  ->from('[email protected]', 'Support team');

// Get mailer from DI (see initializatio section)
$mailer = \Phalcon\Di::getDefault()->get('mailer');

$mailer->setDraftMail($defaultMail);

$mail = new Mail();
$mail
  ->to('[email protected]')
  ->subject('Simple subject')
  ->text('Simple text part message');
  
$mail->send();

// Initialize manager with mail and view services from DI
$mailer = new \Rotoscoping\Phalcon\Manager('mail', 'view');

// template email_confirmation.phtml in your viewDir
$mailer->send(
  // view path
  'email_confirmation',
  // Swift params
  [
    'subject' => 'Example email confirmation',
    'from' => '[email protected]',
    'to' => '[email protected]'
  ],
  // View params
  [ 
    'username' => 'User Name',
    'token' => 'aq1sw2de3'
  ]
);

// word of the send from the beginning and the template filename in camelCase notation
$mailer->sendEmailConfirmation(
  [
    'subject' => 'Example email confirmation',
    'from' => '[email protected]',
    'to' => '[email protected]'
  ],
  [
    'username' => 'User Name',
    'token' => 'aq1sw2de3'
  ]
);