Jump to content

[SOLVED] How to send Custom email with attachment


Recommended Posts

I have code to send email in my module... and email working..

i have file and also file path. But don't know how to attach file with it.????

Here is code:
 

$currency = $this->context->currency;
$customer = new Customer((int)$order->id_customer);
$params['{lastname}'] = $customer->lastname;
$params['{firstname}'] = $customer->firstname;
$params['{order_name}'] = $res_main["reference"];
$params['{pm_reference}'] = $xml->pm_reference;
$params['{way_bill}'] = $xml->label_url;
$params['{voucher_num}'] = $message;
 
$customer = new Customer((int)$order->id_customer);
@Mail::Send((int)$order->id_lang, 'payment_pm', sprintf(Mail::l('Way Bill is Attached%s', (int)$order->id_lang), $order->reference),
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null,
$null, _PS_MAIL_DIR_, true, (int)$order->id_shop);

the file path is:
_PS_ROOT_DIR_.'/administration/'.$order->id.'_'.$product['id_product'].'.pdf'

Please Attach this file in the email.. 

All suggestions are appreciated>.....
thanks in advance.....
Edited by arslantabassum (see edit history)
Link to comment
Share on other sites

Attachment comes right after "from_name"

 

public static function 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)
 
You have to upload the file to the server first, then pass its path instead of null to that parameter
  • Like 1
Link to comment
Share on other sites

 

Attachment comes right after "from_name"

 

public static function 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)
 
You have to upload the file to the server first, then pass its path instead of null to that parameter

 

 

Thanks  It works Great.....

 

Now the Modified Working Example ......

 

 $fileAttachment['content'] = file_get_contents(_PS_ROOT_DIR_.'/administration/file.pdf'); //File path
    $fileAttachment['name'] = 'WayBill'; //Attachment filename
    $fileAttachment['mime'] = 'application/pdf'; //mime file type
 
$currency = $this->context->currency;
$customer = new Customer((int)$order->id_customer);
$params['{lastname}'] = $customer->lastname;
$params['{firstname}'] = $customer->firstname;
$params['{order_name}'] = $res_main["reference"];
$params['{pm_reference}'] = $xml->pm_reference;
$params['{way_bill}'] = $xml->label_url;
$params['{voucher_num}'] = $message;
 
$customer = new Customer((int)$order->id_customer);
@Mail::Send((int)$order->id_lang, 'payment_pm', sprintf(Mail::l('Way Bill is Attached%s', (int)$order->id_lang), $order->reference),
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, $fileAttachment,
null, _PS_MAIL_DIR_, true, (int)$order->id_shop);

 

 

 

Thanks Once Again....... :)

  • Like 2
Link to comment
Share on other sites

×
×
  • Create New...