php - Problem receiving message in production with Mailer
Get the solution ↓↓↓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.
Answer
Solution:
It's good I found. I put the solution if some faced the problem. My concern came from From. The FROM must always be a mailbox of the domain where the site is located and I retrieved from my From the email address entered in my form fields.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: fastcgi sent in stderr: "primary script unknown" while reading response header from upstream
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.