IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

phpMailer en production [4.x]


Sujet :

Symfony PHP

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2020
    Messages : 32
    Points : 32
    Points
    32
    Par défaut phpMailer en production
    Bonjour,
    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/c...=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/c...=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 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    **
        * @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 le .env :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    # 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 ###

  2. #2
    Membre habitué
    Homme Profil pro
    Developpeur
    Inscrit en
    Juillet 2014
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Developpeur

    Informations forums :
    Inscription : Juillet 2014
    Messages : 102
    Points : 153
    Points
    153
    Par défaut
    Bonjour,
    Tu modifies bien le .env qui est sur le serveur de production ? Puis éxecution d'un cache:clear (ou suppression manuelle des fichiers) et un petit redémarrage apache pour être carré.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2020
    Messages : 32
    Points : 32
    Points
    32
    Par défaut
    Re, merci pour tes réponses oui j'ai bien modifier le .env à priori ( à moins que je me soit planté dans les identifiants ). Le truc pour cache:clear c'est que en ssh j'ai pas accès à php bin/console sur le serveur de prod, la commande ne fonctionne pas. Je suis donc allé supprimmé manuellement le dossier cache situé dans le dossier var, mais sa na rien changé. Le truc c'est qu'en dev j'utilisait symfony/google-mailer pour envoyer les mails ( sa fonctionnait nickel ) mais vu que je veux utiliser le mail associé à mon de domaine, je dois plus passer par ce service. Du coup j'ai essayer ( en ssh ) un composer remove symfony/google-mailer, qui n'a pas fonctionné parce que soit disant il n'était pas installé sur le serveur. Donc pour essayer de contourner le truc, je suis allé le supprimé manuellement dans le composer.json, et dans le vendor ( sur le serveur ). Et maintenant j'ai même plus accès a la page d'inscription, j'ai une erreur 500 direct qui dit :
    request.CRITICAL: Uncaught PHP Exception LogicException: "Unable to send emails via Gmail as the Google bridge is not installed. Try running "composer require symfony/google-mailer"." at /home/clients/d0d53a0866a32830e15c23ee9bb5669b/web/vendor/symfony/mailer/Transport.php line 94 {"exception":"[object] (LogicException(code: 0): Unable to send emails via Gmail as the Google bridge is not installed. Try running \"composer require symfony/google-mailer\". at /home/clients/d0d53a0866a32830e15c23ee9bb5669b/web/vendor/symfony/mailer/Transport.php:94)"} []

  4. #4
    Membre habitué
    Homme Profil pro
    Developpeur
    Inscrit en
    Juillet 2014
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Developpeur

    Informations forums :
    Inscription : Juillet 2014
    Messages : 102
    Points : 153
    Points
    153
    Par défaut
    C'est normal que tu ai cette erreur car l'autoload généré par composer doit encore avoir la ligne correspondant à google-mailer
    Peux tu partager le contenu du fichier config/swiftmailer.yaml ?

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2020
    Messages : 32
    Points : 32
    Points
    32
    Par défaut
    oui le voila :
    Code yaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    swiftmailer:
        url: '%env(MAILER_URL)%'
        spool: { type: 'memory' }
    après j'utilise phpmailer pour envoyer les mails

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2020
    Messages
    32
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2020
    Messages : 32
    Points : 32
    Points
    32
    Par défaut
    Du coup je regardais ce matin, j'ai pas trouvé de fichier concernant google-mailer, ni de ligne dans le composer.lock, je me suis rappelé que j'avais utilisé l'extension league/oauth2-google. J'ai rien trouvé non plus ( j'ai même essayer de le désinstallé via composer, qui me dit que ni google-mailer ni league/oauth2-google ne sont installés ), j'ai aussi essayer un composer install et update pour mettre à jour au cas ou. Je sèche complètement. Comment retrouver la ligne qui merde. Il doit forcément y en avoir une quelque part. J'ai aussi regardé du coté des fichiers de config de phpmailer mais j'ai rien vu qui semble correspondre. EDIT : sa y est j'ai enfin réussi !!! En fait en plus de mon .env j'ai un fichier .env.local.php dans lequel l'adresse mail spécifiée était encore l'ancienne ( donc gmail ) après avoir corrigé sa manuellement, sa fonctionne. Sujet résolu merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. envoi de mail avec PHPMAILER
    Par laurentSc dans le forum Langage
    Réponses: 5
    Dernier message: 13/01/2014, 17h50
  2. Envoie de mail avec PHPmailer
    Par Invité dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 09/08/2013, 17h14
  3. envoi de mail avec PHPMailer
    Par laurentSc dans le forum Langage
    Réponses: 9
    Dernier message: 22/05/2013, 15h56
  4. envoi de mail avec phpmailer inopérant
    Par laurentSc dans le forum Langage
    Réponses: 5
    Dernier message: 15/04/2013, 22h31
  5. [Mail] PHP et envoi d'email avec PHPmailer
    Par dolf13 dans le forum Langage
    Réponses: 6
    Dernier message: 14/07/2006, 00h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo