Documentation


SMTP mailing

The framework provides an interface to the PHPMailer package. Like the mail() wrapper you can send HTML content by specifying views. Except it uses SMTP protocol to send mails. This requires an SMTP service running on a server.

The following environment variables need to be adjusted:

  • SMTP_HOST: Hostname or address of the SMTP server
  • SMTP_PORT: Port to connect through, e.g. 587 for TLS encrypted connection
  • SMTP_USERNAME: Login name for the server
  • SMTP_PASSWORD: Login password for the server
  • SMTP_ENCRYPTION: Either ‚tls‘ or ‚smtps‘.

The following example demonstrates how to use the functionality

<?php

//Instantiate class instance
$mailer = new Asatru\SMTPMailer\SMTPMailer();

//Here you set the recipient of the e-mail
$mailer->setRecipient('receiver@example.com');

//E-Mail subject
$mailer->setSubject('E-Mail subject');

//Specify a view
$mailer->setView('layout', array(array('yield', 'yieldfile')), [
    'some_var' => $some_value
]);

//Or specifiy the content directly
$mailer->setMessage('Content goes here...');

//If desired, you can also overwrite PHPMailer properties.
$mailer->setProperties([...]);

$mailer->send(); //Send the e-mail

Of course you can directly access PHPMailer class for custom e-mailing.