Mailer

The Quantum provides a mailer feature based on the popular PHPMailer library and makes the email sending process very easy.

To start using the Mailer library you need to make it available in your controller


        use Quantum\Libraries\Mailer\Mailer;
        
        

If you want to send an email from your host, which means the mail server installed and running on your server, the Mailer library will act like PHP's mail() function.

If you want to send an email via SMTP, you will need to add several variables into .env file related to SMTP server.

  • MAIL_HOST - SMTP host
  • MAIL_SMTP_SECURE - Encryption (ssl or tls)
  • MAIL_PORT - SMTP server port
  • MAIL_USERNAME - SMTP username
  • MAIL_PASSWORD - SMTP password

Now you need to create an instance of Mailer:


        $mailer = new Mailer();
        
        

And then send an email using send() method:


        $mailer->send($from, $address, $message, $options);
        
        

The method send() accepts four parameters:

  • $from <Array> - Sets the From and FromName properties.
    
        $from = ['email' => 'john.doe@gmail.com', 'name' => 'John Doe'];
    
                    
  • $addresses <Array> - Sets a "To" addresses
    
        $address = ['email' => 'jane.doe@gmail.com', 'name' => 'Jane Doe'];
    
                    
    OR
    
    $address = [
        ['email' => 'jane.doe@gmail.com', 'name' => 'Jane Doe'],
        ['email' => 'pompies@hotmail.com', 'name' => 'Piet Pompies']
    ],
    
                    
  • $message <Mixed> - The message body
    
    $message = '<p>Hi there, This is a really simple email template. Good luck! Hope it works.<p>';
    
                    
    OR when using template
    
    $message = [
        'greetings' => 'Hi there',
        'text' => 'This is a really simple email template.',
        'ps' => 'Good luck! Hope it works.',
        'button' => 'Call To Action',
        'href' => 'http://softberg.org'
    ];
    
                    
  • $options <Array> - Optional parameters
    • subject <String> - The email subject
    • template <String> - Path to the template file (from current module)
    • attachments <Mixed> - Path to the attachment file (from public directory)
      
      $options = [
          'attachments' => 'uploads/fonts.zip'
      ]
      
                              
      OR
      
      $options = [
          'attachments' => [
              'uploads/fonts.zip', 
              'uploads/schema.pdf'
          ]
      ]
      
                              
    • replayto <Mixed> - Sets a "Reply-To" addresses
      
      $options = [
          'replayto' => 'jane.doe@gmail.com',
      ]
      
                              
      OR
      
      $options = [
          'replayto' => [
              'jane.doe@gmail.com',
              'pompies@hotmail.com'
          ]
      ]
      
                              
    • cc <Mixed> - Sets a "CC" addresses
      
      $options = [
          'cc' => 'jane.doe@gmail.com',
      ]
      
                              
      OR
      
      $options = [
          'cc' => [
              'jane.doe@gmail.com',
              'pompies@hotmail.com'
          ]
      ]
      
                              
    • bcc <Mixed> - Sets a "BCC" addresses
      
      $options = [
          'bcc' => 'jane.doe@gmail.com',
      ]
      
                              
      OR
      
      $options = [
          'bcc' => [
              'jane.doe@gmail.com',
              'pompies@hotmail.com'
          ]
      ]
      
                              
<< Prev Next >>