Jump to content

Solution : Bug d'envoi des mails dans les 2 formats


Recommended Posts

Bonjour,

Dans le Back office, onglet "Préférences" > "E-mails", vous avez la possibilité de choisir d'envoyer, les mails en html, en texte ou les deux.
Il peut être utile d'envoyer les mails dans les 2 formats pour être certain que les mails soient reçus (les mails en html peuvent être considérés comme spam).

Si vous choisissez "les deux", vous constaterez que seul le mail en html est envoyé.

Pour corriger cela, ouvrez le fichier classes>Mail.php

et remplacez :

/* Create mail and attach differents parts */
           $message = new Swift_Message('['.Configuration::get('PS_SHOP_NAME').'] '.((is_array($_LANGMAIL) AND key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
           $templateVars['{shop_logo}'] = (file_exists(_PS_IMG_DIR_.'logo.jpg')) ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.'logo.jpg'))) : '';
           $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
           $templateVars['{shop_url}'] = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__;
           $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
           if ($configuration['PS_MAIL_TYPE'] == 3 OR $configuration['PS_MAIL_TYPE'] == 2)
               $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
           if ($configuration['PS_MAIL_TYPE'] == 3 OR $configuration['PS_MAIL_TYPE'] == 1)
               $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
           if ($fileAttachment AND isset($fileAttachment['content']) AND isset($fileAttachment['name']) AND isset($fileAttachment['mime']))
               $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
           /* Send mail */
           $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
           $swift->disconnect();
           return $send;



Par

/* Create mail and attach differents parts */
           $message = new Swift_Message('['.Configuration::get('PS_SHOP_NAME').'] '.((is_array($_LANGMAIL) AND key_exists($subject, $_LANGMAIL)) ? $_LANGMAIL[$subject] : $subject));
           $templateVars['{shop_logo}'] = (file_exists(_PS_IMG_DIR_.'logo.jpg')) ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_.'logo.jpg'))) : '';
           $templateVars['{shop_name}'] = htmlentities(Configuration::get('PS_SHOP_NAME'), NULL, 'utf-8');
           $templateVars['{shop_url}'] = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__;
           $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');

           if ($configuration['PS_MAIL_TYPE'] == 3 OR $configuration['PS_MAIL_TYPE'] == 2)
               {
       $message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
       if ($fileAttachment AND isset($fileAttachment['content']) AND isset($fileAttachment['name']) AND isset($fileAttachment['mime']))
               $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
             /* Send mail */
             $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
       }
           if ($configuration['PS_MAIL_TYPE'] == 3 OR $configuration['PS_MAIL_TYPE'] == 1)
               {
       $message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
       if ($fileAttachment AND isset($fileAttachment['content']) AND isset($fileAttachment['name']) AND isset($fileAttachment['mime']))
               $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
             /* Send mail */
             $send = $swift->send($message, $to, new Swift_Address($from, $fromName));
             }

           $swift->disconnect();
           return $send;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...