Jump to content

Help, attach a pdf file to the order confirmation email


Recommended Posts

Hi,

have already managed to attach a pdf file to the registration confirmation email with the following code:

 

email to verify (free module for customers to receive a confirmation link) I modified

 

				 if (!Mail::Send((int)$cookie->id_lang,
				'emailverify',
				Mail::l('Welcome!', (int)$cookie->id_lang),
				array('{firstname}' => $customer->firstname,
				'{lastname}' => $customer->lastname,
				'{email}' => $customer->email,
				'{passwd}' =>  Tools::getValue('passwd'),
				'{actlink}' => $actlink),
				$customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, dirname(__FILE__).'/mails/')
				)

 

with

 

			 $file = _PS_ROOT_DIR_ . '/terms_of_use.pdf'; // File name with no spaces no accents !!!
		    $fileAttachment['content'] = file_get_contents($file);
		    $fileAttachment['name'] = 'Terms Of Use.pdf'; // Name of attachement (no accents !!!)
		    $fileAttachment['mime'] = 'application/pdf'; // Mime type of attachement
		    if (!Mail::Send((int)$cookie->id_lang,
			    'emailverify',
			    Mail::l('Welcome!', (int)$cookie->id_lang),
			    array('{firstname}' => $customer->firstname,
			    '{lastname}' => $customer->lastname,
			    '{email}' => $customer->email,
			    '{passwd}' =>  Tools::getValue('passwd'),
			    '{actlink}' => $actlink),
			    $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment, NULL, dirname(__FILE__).'/mails/')
			    )

 

Let me know if you have ideas on how to attach the same pdf file to the order confirmation email, suggestions?

 

thanks and sorry for the bad English

Link to comment
Share on other sites

Solved,

I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code:

 

if ($template == 'it/order_conf')
	    $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf';
	    $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf'));

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
  • 1 month later...

Solved,

I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code:

 

if ($template == 'it/order_conf')
		    $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf';
		    $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf'));

 

Hi this workes great with some exceptions. The PDF is attached but with 0 KB and if i try to open it .

 

Any Ideas what this could be?

 

Greetz and Thank you!!

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...

Solved,

I added to the file mail.php (path yoursite \ classes \ mail.php) at line 270 or so, before the comment / * send email * /, this code:

 

if ($template == 'it/order_conf')
		    $file = _PS_ROOT_DIR_ . '/file_da_allegare.pdf';
		    $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'file_da_allegare.pdf', 'application/pdf'));

 

Prestashop 1.6.0.14

 

It does not work.

 

Link to comment
Share on other sites

  • 6 months later...
  • 3 months later...

I can't get this to work (using 1.6.0.14). Here is my code:

// Multiple attachments?
				if (!is_array(current($file_attachment)))
					$file_attachment = array($file_attachment);

				foreach ($file_attachment as $attachment)
					if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime']))
						$message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
			}
 
// Your terms of service pdf                    
$file_attachment['content'] = file_get_contents(_PS_ROOT_DIR_.'/dokumenti/file.pdf');
$file_attachment['name'] = 'file.pdf';
$file_attachment['mime'] = 'application/pdf';
			/* Send mail */

Does anything else must be Please help!!!

Link to comment
Share on other sites

  • 2 weeks later...

Patching core PrestaShop code is not the best approach. It can collide with other code or modules and you have to apply the patch again after every upgrade.

 

I suggest to use one PDF attachment (invoice) and add another page(s) to it. Alternatively, you can just put a link to a static PDF document to download.

Link to comment
Share on other sites

  • 11 months later...

Hello, I have a problem similar to the one above. My problem is that I need to add more than file in the email attachment, but I can not, I can upload the two attachments but I can not send it by email. My code is as follows:

for ($i=0; $i <count($_FILES['FILE']['name']); $i++) { if(!isset($_FILES['FILE'][$i]) or !($_FILES['FILE']['size'][$i] > 0)) { $this->_error .= $this->displayError($this->l('Invalid file')); } $explode = explode('.', $_FILES['FILE']['name'][$i]); $ext = end($explode); if(!in_array($ext, array('pdf','doc', 'docx', 'rar', 'zip')) ) { $this->_error .= $this->displayError($this->l('Invalid file extension')); } else { $tmpFilePath[$i] = $_FILES['FILE']['tmp_name'][$i]; if ($tmpFilePath != ""){ $newFilePath[$i] = dirname(__FILE__ ).'/import/' . $_FILES['FILE']['name'][$i]; if(move_uploaded_file($tmpFilePath[$i], $newFilePath[$i])) { $file_name[$i] = $_FILES['FILE']['name'][$i]; $file_size[$i] = $_FILES['FILE']['size'][$i]; $tmp_name[$i] = $_FILES['FILE']['tmp_name'][$i]; $file_type[$i] = $_FILES['FILE']['type'][$i]; // attachment $handle = fopen($newFilePath[$i], "r"); $content = fread($handle, $file_size[$i]); fclose($handle); $content = $content; } } } } $sql1 = 'SELECT `envio_recibo` FROM `'._DB_PREFIX_.'contabilidade_faturacao` WHERE `id_contabilidade_faturacao` ='.$id_contabilidade_faturacao; $value = Db::getInstance()->ExecuteS($sql1); foreach($value as $key => $res) {$envio_recibo = $res['envio_recibo'];} if($envio_recibo == 0) { $res = Mail::Send( $this->context->language->id, 'recibos', $subject, array('{message}' => $msg_html, $template_vars = false,), $to, $to_name, $from, $from_name, array('content' => $content, 'mime' => 'application/pdf', 'name' => $file_name[$i]), null, $this->local_path.'mails/', null, null, $bcc, null );

(continue)

 

Do not call my texts because I am Portuguese and they are Portuguese. Can someone give me a hand?

Hello, I have a problem similar to the one above. My problem is that I need to add more than file in the email attachment, but I can not, I can upload the two attachments but I can not send it by email. My code is as follows: Can someone give me a hand?

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...