Problem receiving message in production with Mailer

Good morning all,

I am under symfony 4.4.

I use Mailer to send mails.

I have two cases in my applications. I can send an email to each member of the association.

And I can send bulk mails which I called convocation.

Both work locally, mailhog retrieves my emails well.

But in production I have no errors I am told that everything is sent, however, only emails from individual contacts reach the recipients but not all the time.

The invitations do not arrive but the only difference between the two is that there are several emails for the invitations and the template which has an image.

I’m on 02switch. I used all the recommended ports but they are the same: 465,26,25.

My mailer.yaml:

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%

my .env:

###> symfony/mailer ###
MAILER_DSN=smtp://lettonie.o2switch.net:26
###< symfony/mailer ###

my controller for individual contact:

 $formcontact = $this->createForm(AdherentContactType::class);
        $contact = $formcontact->handleRequest($request);
        if($formcontact->isSubmitted() && $formcontact->isValid()){
            $email = (new TemplatedEmail())
            ->from($contact->get('email')->getData())
            ->to($adherent->getEmail())
            ->subject('contact')
            ->htmlTemplate('emails/contact_adherent.html.twig')
            ->context([
                'adherent' =>$adherent,
                'mail' => $contact->get('email')->getData(),
                'message'=> $contact->get('message')->getData()
            ]);
            $mailer->send($email);
            $this->AddFlash(
                'success',
                "Votre email a bien été envoyé !"
            );
            return $this->redirectToRoute('adherent_show',['id' => $adherent->getId()]);
        }

My template for individual contacts:

<h1>Contact</h1>
<p>De : {{ mail }}</p>
 
<p>Message: {{ message|raw }}</p>

My controller for my invitations:

if($team->getAdherents()!= null) {
        foreach ($team->getAdherents() as $c) {
            if($c->getEmail() != null){
                $mails[] = $c->getEmail();
            }
             
        }
    }
        if (isset($mails)) {
            $mails = array_combine($mails , $mails);
        }
        
      //var_dump($mails);exit();
   
     
           /***formulaire de contact*******/
           if (isset($mails)) {
           $formcontact = $this->createForm(ConvocationType::class,$mails,[
            'mails' => $mails,
        ]);
            
           $contact = $formcontact->handleRequest($request);
           if($formcontact->isSubmitted() && $formcontact->isValid()){
 
             
             
            foreach ($contact->get('emailTo')->getData() as $c) {
                if($c != NULL){
                $emails[]= $c;} // Ou autre selon la fonction de ta class Adhérent   
                else {
                $emails[]= null;}
                }
   // dump($emails);exit;
             if(isset($mails) and isset($emails)){
               $email = (new TemplatedEmail())
               ->from($contact->get('email')->getData())
               ->to(...$emails)
               ->subject('contact')
               ->htmlTemplate('emails/convocation_match.html.twig')
               ->context([
                  'catadherent' =>$catadherent,
                  'mail' => $contact->get('email')->getData(),
                  'mailTo'=>$contact->get('emailTo')->getData(),
                  'team'=> $team->getName(),
                  'convocation_date'=>$contact->get('convocation_date')->getData(),
                  'club_adverse'=>$contact->get('club_adverse')->getData(),
                  'rendez_vous_date'=>$contact->get('rendez_vous_date')->getData(),
                  'lieu'=>$contact->get('lieu')->getData(),
                  'match_date'=>$contact->get('match_date')->getData(),
                  'stade'=>$contact->get('stade')->getData(),
 
               ]);
               $mailer->send($email);
               $this->AddFlash(
                   'success',
                   "Votre email a bien été envoyé !"
               );
               //return $this->redirectToRoute('adherent_show',['id' => $adherent->getId()]);
              }
              else{
                $this->AddFlash(
                    'danger',
                    "Votre email n'a pas été envoyé car aucun mail n'a été sélectionné !"
                );
              }
            }
        }

my branch template for my invitations:

{# '@images/' refers to the Twig namespace defined earlier #}
<center><img src="{{ email.image('@images/logo/uspeg-tr.gif') }}" width="200" height="200" alt="Logo">
<h1>Convocation</h1>
<p>De : {{ mail }}</p>
<div>
Equipe:{{team}}            
</div>
<div>
<p>Tu es convoqué le <strong>{{convocation_date|date("d/m/Y") }}</strong>  pour le match contre <strong>{{club_adverse}}</strong> ».</p><br>
 
<p>Le rendez-vous est fixé le <strong>{{rendez_vous_date|date("d/m/Y à G:i") }}</strong> au <strong>{{ lieu }}</strong>.</p><br>
 
<p>Le match se déroulera le <strong>{{ match_date|date("d/m/Y à G:i") }}</strong>  précise au stade <strong>{{ stade }}</strong>.
</p>
<br>
<p style="color:red;"><strong> Prévenir impérativement l’éducateur en cas d’empêchement le plus tôt possible.</strong></p>
</div></center>

I don’t really know what the problem might be.

Does somebody have an idea?

Thank you in advance.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *