Jump to content

Does somebody know How to add several attached files in email using Mail::Send function


Recommended Posts

Hi,

Does somebody know How to add several attached files in emaill using Mail::Send function ?

I'm looking for this solution to send several PDF files in an email sending by a module.

 

Please let me know if you have the solution!

 

Kriss

Link to comment
Share on other sites

I thought that somebody of the PS community could give me some help and tell me how to modify the mail class.

 

For exple I think about a code modification of the send function, but I think that there are more modification to add if I want to get the possibility to send 10 attached files in a email

 

Code now :

 

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']));

 

Remplaced by something like:

 

 

foreach ($filesAttachment as $fileAttachment)

if (isset($fileAttachment['content']) AND isset($fileAttachment['name']) AND isset($fileAttachment['mime']))

                                $message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));

 

 

Link to comment
Share on other sites

  • 11 years later...

If anyone is looking for an updated answer, I have actually made a solution for PrestaShop 8.1.0, because I needed to develop a way to attach a PDF-file with Terms & Conditions to the order-confirmation-email.

To do this, I simply made an override for the Mail.php-class and the magic was essentially done by these lines:

        if ($template == 'order_conf'){                        
            $message->attach(Swift_Attachment::fromPath('TermsAndConditions.pdf'));
        }

(where the PDF-file called "TermsAndConditions.pdf" must be placed in the root folder of the site)

 

To make this solution, I created a file called Mail.php in the folder "\override\classes" of the PrestaShop-installation.

In this file, I created a class that started with this line:

class Mail extends MailCore {

and then inside that class, I pasted the (entire) public static function called "send()", which I copied from \classes\Mail.php of the PrestaShop-installation.

So, open the file \classes\Mail.php and copy the entire send()-function, which starts around line 132 and ends around line 669 - and then paste this function into the new extension class in "\override\classes\Mail.php", as mentioned above.

And then insert these new lines:

        if ($template == 'order_conf'){                        
            $message->attach(Swift_Attachment::fromPath('TermsAndConditions.pdf'));
        } 

right above these lines (found somewhere around line 505 in the new file, and line 604 in the original file, respectively):

            if (!empty($fileAttachment)) {
                // Multiple attachments?
                if (!is_array(current($fileAttachment))) {

 

And then make sure that you have a PDF-file in the site's root-folder called TermsAndConditions.pdf ;)

 

If you want to know more about attaching files with Swift-mailer, you can find pretty good info here: https://swiftmailer.symfony.com/docs/messages.html#attaching-files

 

Also, I would have liked to simply share my entire override-file to make it easier for you, but this forum-software wouldn't allow me to do so (maybe because of a faulty Cloudflare-implementation on prestashop.com). Someone should really look into this issue, as it prevents people from sharing solutions with each other. Not good for the open source community!!

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...