Symfony Send email to multiple recipients SwiftMailer - Hack The Tech - Latest News related to Computer and Technology

logo

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, June 4, 2021

demo-image

Symfony Send email to multiple recipients SwiftMailer

I am using symfony(a beginner ) and I am trying to send an email with swiftmailer I have a class "campagne" that contains the email campaigns I want to send , and a class "groupe" (each group contains email addresses to which i want to send the campaigns) with a ManytoMany relation between the 2

My question is : how can I send my campaigns to the emails in the group I choose

send function :

$campagne = $this->getDoctrine()->getRepository(Campagne::class) ->find($id);
     $message = (new \Swift_Message($campagnes->getNom()))
                             // On attribue l'expéditeur
                             ->setFrom('expedmail@gmail.com')
                             // On attribue le destinataire
                        
                             ->setTo('recipmail@gmail.com')
                            
                             // On crée le texte avec la vue
                             ->setBody($campagne->getMessage() );
                             $mailer->send($message);

and I have this in the "Campagne" Entity :

 /**
     * @return Collection|Groupe[]
     */
    public function getCampagnes(): Collection
    {
        return $this->campagnes;
    }


source https://stackoverflow.com/questions/67826668/symfony-send-email-to-multiple-recipients-swiftmailer

No comments:

Post a Comment