krs21 Posted February 16, 2012 Share Posted February 16, 2012 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 More sharing options...
bellini13 Posted February 17, 2012 Share Posted February 17, 2012 the Mail::Send function only allows for sending a single attachment currently. It would need to be overridden to allow a module to send in multiple attachment files. Link to comment Share on other sites More sharing options...
krs21 Posted February 19, 2012 Author Share Posted February 19, 2012 Do you have the code to implement as override to send multiple attachment files because I'm a newbie ? Link to comment Share on other sites More sharing options...
bellini13 Posted February 20, 2012 Share Posted February 20, 2012 no, I have not altered it. If you would like to hire me for this, you can send me a PM with the details of what you are trying to accomplish. Link to comment Share on other sites More sharing options...
krs21 Posted February 21, 2012 Author Share Posted February 21, 2012 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 More sharing options...
LarsM Posted August 8, 2023 Share Posted August 8, 2023 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now