Jump to content

[Tutorial] Adding attchement to mailalerts : New Order Message


Recommended Posts



Here is how I did it:

in the function Main::send() , attachement is in the 9 position, variable number 9.

So in mailalerts count till variable 9 wich correspond to null by default. 

And then use this:

// Join PDF invoice
$id_order_state = Configuration::get('PS_OS_ERROR');
$order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id);
if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number)
$pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $this->context->smarty);
$file_attachement['content'] = $pdf->render(false);
$file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf';
$file_attachement['mime'] = 'application/pdf';


$file_attachement =null;


//So change myfile.pdf  to your file name.
//And here you go:
if ($dir_mail)
                    sprintf(Mail::l('New order : #%d - %s', $mail_id_lang), $order->id, $order->reference),                            

I just relaced the null to $attach . 


Here is the function that sends mails with all its variables:

	 * Send Email
	 * @param int $id_lang Language of the email (to translate the template)
	 * @param string $template Template: the name of template not be a var but a string !
	 * @param string $subject
	 * @param string $template_vars
	 * @param string $to
	 * @param string $to_name
	 * @param string $from
	 * @param string $from_name
	 * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
	 * @param bool $modeSMTP
	 * @param string $template_path
	 * @param bool $die
     * @param string $bcc Bcc recipient
	Mail::Send($id_lang, $template, $subject, $template_vars, $to,
		$to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null,
		$template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null);

So we are dealing with:

$file_attachment = null,
Edited by ndiaga (see edit history)

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More