JMail::addAttachment() :: parameter 1?

319 views
Skip to first unread message

hoochicken

unread,
Mar 25, 2014, 7:47:18 AM3/25/14
to joomla-de...@googlegroups.com
Hi girls, hi guys,

I want to send e-mails with an attachment.
Background: a file via form is uploaded and then sent so recipient.

It seems to me that the JMail::addAttachment() method might be just what I need, but I just can't find out, what the params mean.
All params a obsolete except the first one which is described as a string (or array) containing the attachment(s) (oder attachment name(s)?).
Anybody an idea?

Greetings
Mareike

PS: Here description from API

addAttachment

Add file attachments to the email

addAttachment(mixed $attachment, mixed $name = '', mixed $encoding = 'base64', mixed $type = 'application/octet-stream') : \JMail
since

11.1



Arguments

$attachment

mixedEither a string or array of strings [filenames]

$name

mixedEither a string or array of strings [names]

$encoding

mixedThe encoding of the attachment

PPS: The method is part of the sendMail() J! core function - but J! core never uses the sendMail() to attach files, so I just can't find a proper example.
com_akeebackup uses it exactly once, but I couldn't figure out how either:-(

Tuan Pham Ngoc

unread,
Mar 26, 2014, 4:40:23 AM3/26/14
to joomla-de...@googlegroups.com
Hi

The parameter can be a string or an array :

1. if it is a string, that string must be the absolute path to the file you want to send in the email.

2. if it is an array, each element in that array must be the absolute path to the file you want to send. In this case, multiple attachments will be sent in the email.

A sample code which I use to send email with attachment can be found below :

$mailer = JFactory::getMailer();
$attachment = JPATH_ROOT.'/myfile.pdf'; //As mentioned, this is the absolute path to the file
$mailer->sendMail($fromEmail, $fromName, $row->email, $subject, $body, 1, null, null, $attachment);

Hope that helps !

hoochicken

unread,
Mar 28, 2014, 3:29:51 AM3/28/14
to joomla-de...@googlegroups.com
Hi Tuan,
that did it, Great, Thank you so much!
Greetings
Mareike
Reply all
Reply to author
Forward
0 new messages