PHP code example of khaleejinfotech / multi-tenant-mailer

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

    

khaleejinfotech / multi-tenant-mailer example snippets


   'providers' => [
       // ...
       Khaleejinfotech\MultiTenantMailer\MultiTenantMailerServiceProvider::class,
   ],

3. **Publish Configuration:** After installation, publish the configuration file and any 

return [
    'queue_class' => \Khaleejinfotech\MultiTenantMailer\Jobs\MultiTenantMailerQueued::class,
];

use Khaleejinfotech\MultiTenantMailer\MultiTenantMailer;

$mailer = new MultiTenantMailer();
$mailer->init($host, $port, $username, $password, $encryption);

$mailer->setFrom($fromAddresses, $fromName)
  ->setTo($toAddresses, $toName)
  ->setSubject($subject)
  ->setBody($body)
  ->setContentType('text/html')
  ->setAttachments($attachments)
  ->shouldQueue(); // Optional: Set to true if you want to queue the email

$mailer->send();

use Khaleejinfotech\MultiTenantMailer\Contracts\MultiTenantMailerSettings;

$mailerSettings = new MultiTenantMailerSettings();
$mailerSettings->setHost($host)
   ->setPort($port)
   ->setUsername($username)
   ->setPassword($password)
   ->setEncryption($encryption)
   ->setFromAddress($fromAddress, $fromName);

use Khaleejinfotech\MultiTenantMailer\MultiTenantMailer;

$mailer = new MultiTenantMailer();
$mailer->withSettings($mailerSettings);

use Khaleejinfotech\MultiTenantMailer\Facades\MultiTenantMailer;

MultiTenantMailer::init($host, $port, $username, $password, $encryption)
  ->setFrom($fromAddresses, $fromName)
  ->setTo($toAddresses, $toName)
  ->setSubject($subject)
  ->setBody($body)
  ->setContentType('text/html')
  ->setAttachments($attachments)
  ->shouldQueue()
  ->send();

use Khaleejinfotech\MultiTenantMailer\Facades\MultiTenantMailerSettings;

MultiTenantMailerSettings::setHost($host)
  ->setPort($port)
  ->setUsername($username)
  ->setPassword($password)
  ->setEncryption($encryption)
  ->setFromAddress($fromAddress, $fromName);

public function via(object $notifiable): array
{
    return ['tenant_mailer'];
}

public function toTenantMailer($notifiable): MultiTenantMailer
{
    return (new MultiTenantMailer)
        ->setHost(config('mail.mailers.smtp.host'))
        ->setPort(config('mail.mailers.smtp.port'))
        ->setUsername(config('mail.mailers.smtp.username'))
        ->setPassword(config('mail.mailers.smtp.password'))
        ->setEncryption(config('mail.mailers.smtp.encryption'))
        ->setFrom(config('mail.from.address'))
        ->setTo($notifiable)
        ->setSubject('Subject')
        ->setBody($this->toMail($notifiable)->render());
}

->setBody(new MailTestMessge()); 

->setBody($this->toMail($notifiable)->render()); 

->onQueue('emails');