PHP code example of 2lenet / mailer-bundle

1. Go to this page and download the library: Download 2lenet/mailer-bundle 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/ */

    

2lenet / mailer-bundle example snippets


    function index(MailerManager $mailerManager) {

        $destinataires = [
            '[email protected]' => ["nom" =>"Sébastien"],
            '[email protected]' => ["nom" =>"Jules"]
        ];
        
        $mail = $mailerManager->create('TEST', $destinataires); // create mail for all destinataires
        $mailerManager->send($mail);  // send the mail
    }    



class MailTemplate implements TemplateInterface
{
    use TemplateEntityTrait;
    
}

class Mail implements MailInterface
{
    use MailEntityTrait;

    /**
     * @ORM\ManyToOne(targetEntity="MailTemplate", cascade={"persist"})
     * @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
     */
    protected $template;

    /**
     * @ORM\OneToMany(targetEntity="MailDestinataire",mappedBy="mail", cascade={"persist"})
     */
    protected $destinataires;
}

class MailDestinataire implements DestinataireInterface
{
    use DestinataireEntityTrait;

    /**
     *
     * @ORM\ManyToOne(targetEntity="Mail",cascade={"persist"},inversedBy="destinataires")
     * @ORM\JoinColumn(name="mail_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $mail;

}

 $mail->addAttachment(path/to/your/file);

$mail->addAttachment($this->kernel->getProjectDir() . '/' . $pdf->getPath());

 $mail->addStreamAttachments(String $data, String $filename, String $contentType);

 $mail->removeAllAttachments();

 $mail->getStreamAttachments();