Jump to content

How to send email with attachment


Recommended Posts

Hello.

I want to send an email with an attachment but i have a weird issue. My mail is sent with the message but not the attachment.

I'm stuck, please help me. Here is my code

include('../config/config.inc.php');
require_once(dirname(__FILE__).'/../init.php');

$file_attachment=array();

$content = file_get_contents(_PS_ROOT_DIR_.'/_leptis/PDF_20121109_2.pdf');
$file_attachment['content'] = $content;
$file_attachment['name'] ='RandomPDF';
$file_attachment['mime'] = 'application/pdf';

Mail::Send((int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
'contact', // email template file to be use
'Export auto commandes du xxxxxxx', // email subject
array(
    '{email}' => Configuration::get('PS_SHOP_EMAIL'), // sender email address
    '{message}' => 'This is a test message.', // email content
),
'[email protected]', // receiver email address
null, //Receiver name
Configuration::get('PS_SHOP_EMAIL'), //Sender email
Configuration::get("PS_SHOP_NAME"), // Sender name
$file_attachment, //Attachment
null, //SMTP mode
_PS_MAIL_DIR_, //Mails directory
true //Die after error?
);

 

Link to comment
Share on other sites

  • 7 months later...

The function is like below:

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 

 $file_attachment['content'] = file_get_contents(_PS_ROOT_DIR_.'/_leptis/PDF_20121109_2.pdf'); //File path

Try not to use the $content variable.

Link to comment
Share on other sites

  • 2 weeks later...

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