pendant le développement de mon site, j'utilisais symfony/google-mailer pour envoyer des mails. Maintenant que je suis en production, je veux utiliser le mail associé à mon nom de domaine (contact@bibliocode.fr). Le truc c'est que j'ai beau modifier le .env et spécifier le serveur smtp dans mon controller, je vois dans mes logs de prod :
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" starting [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "220 smtp.gmail.com ESMTP p7sm321798wmp.31 - gsmtp" (ok). [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "EHLO [127.0.0.1]" [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "250-smtp.gmail.com at your service, [2001:1600:4:b:4ed9:8fff:fe9f:bf3] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8" (ok). [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "AUTH LOGIN" [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "334 VXNlcm5hbWU6" (ok). [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "ZGV2LmdvdXY=" [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "334 UGFzc3dvcmQ6" (ok). [] []
[2020-01-20 19:35:59] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "Um9iaW51czMxNDAw" [] []
[2020-01-20 19:36:00] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs 534-5.7.14 anFKZIF2MOTwKqhTnMb6XIXh8k3GiwcpbRuS5V5Z7lG4zwpJpZ1aDbICQgVcmCpKIWoWz 534-5.7.14 oV1k-6bmZ844MgtdaiOullhrszMufpqB5XDCUgZaBUbF7zBTraoJy2L0UAacsVNa> 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 p7sm321798wmp.31 - gsmtp" (error). [] []
[2020-01-20 19:36:00] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "RSET" [] []
[2020-01-20 19:36:00] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "250 2.1.5 Flushed p7sm321798wmp.31 - gsmtp" (ok). [] []
[2020-01-20 19:36:00] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "AUTH PLAIN ZGV2LmdvdXYAZGV2LmdvdXYAUm9iaW51czMxNDAw" [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv 534-5.7.14 zcyOQii1ATA7QPu_vcVsgQCUqIWfQhHLTIh-Wf5husF7tLAohhspGmDBR-2LYsQMV0pWd 534-5.7.14 BTZmJ0cRQsBuwL3AuIu1Px_6hm2meqZ3m0BhRdroj_wGkFpxemzWvWTY7NSzyF-0> 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 p7sm321798wmp.31 - gsmtp" (error). [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "RSET" [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "250 2.1.5 Flushed p7sm321798wmp.31 - gsmtp" (ok). [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "AUTH XOAUTH2 dXNlcj1kZXYuZ291dgFhdXRoPUJlYXJlciBSb2JpbnVzMzE0MDABAQ==" [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==" (error). [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" sent command "RSET" [] []
[2020-01-20 19:36:01] app.DEBUG: Email transport "Symfony\Component\Mailer\Transport\Smtp\SmtpTransport" received response "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials p7sm321798wmp.31 - gsmtp" (error). [] []
[2020-01-20 19:36:01] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Mailer\Exception\TransportException: "Expected response code "250" but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials p7sm321798wmp.31 - gsmtp"." at /home/clients/d0d53a0866a32830e15c23ee9bb5669b/web/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php line 249 {"exception":"[object] (Symfony\\Component\\Mailer\\Exception\\TransportException(code: 535): Expected response code \"250\" but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials p7sm321798wmp.31 - gsmtp\". at /home/clients/d0d53a0866a32830e15c23ee9bb5669b/web/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:249)"} []
donc en gros sa passe toujours par le smtp de gmail. Pourtant je l'ai bien modifié. Pourquoi sa ne marche pas ? Un problème de cache ?
le controller :
/**
* @Route("/change", name="change")
*/
public function changePassword(AuthenticationUtils $authenticationUtils, Request $request, MailerInterface $mailer) {
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$entityManager = $this->getDoctrine()->getManager();
$form = $this->createForm(ResetPasswordType::class);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$user = $entityManager->getRepository(User::class)->findOneByEmail($form->getData()['email']);
if ($user !== null) {
$token = uniqid();
$user->setResetPassword($token);
$user->setTokenDate(new \DateTime());
$entityManager->persist($user);
$entityManager->flush();
$name = $user->getUsername();
$email = (new TemplatedEmail())
->from('contact@bibliocode.fr')
->to($user->getEmail())
->replyTo('contact@bibliocode.fr')
->subject('Changement de mot de passe')
->htmlTemplate('security/changePasswordTemplate.html.twig')
->context([
'name' => $name,
'token' => $token
]);
$email->Host = 'mail.infomaniak.com';
$email->Port = 587;
$mail->Username = 'contact@bibliocode.fr';
$mail->Password = 'xxxxxxxxxx';
$mailer->send($email);
$this->addFlash('success', 'Un email vous a été envoyé');
}
else {
$this->addFlash('erreur', 'Identifiant incorrect');
return $this->redirectToRoute('change');
}
}
return $this->render('biblio/change.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'form' => $form->createView()
]);
}
et .env :
# In all environments, the following files are loaded if they exist,
# the later taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> symfony/framework-bundle ###
APP_ENV=prod
APP_SECRET=732cfc111284bd2aa70ddf7a1a84e216
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://j290a_robinus:motdepasse@j290a.ftp.infomaniak.com:3306/j290a_bibliocodex
###< doctrine/doctrine-bundle ###
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###
###> symfony/mailer ###
MAILER_DSN=smtp://mail.infomaniak.com:587?encryption=&auth_mode=contact:motdepasse@bibliocode
###< symfony/mailer ###
###> symfony/google-mailer ###
# Gmail SHOULD NOT be used on production, use it in development only.
#MAILER_DSN=smtp://dev.gouv:motdepasse@gmail
###< symfony/google-mailer ###
Votre aide me serais d'un grand secours, merci.
- Edité par RobinGouverner 20 janvier 2020 à 19:49:48
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.