J3 Issue ?
avatar Denitz
Denitz
1 Mar 2017

Steps to reproduce the issue

$mailer = JFactory::getMailer();
$mailer->addAttachment([
    $filename => $filepath,
]);

or send email with array of attachments via JFactory::getMailer()->sendMail()

Expected result

Email should have attachment named $filename

Actual result

Email has attachment named $filepath

Additional comments

It's also logical to use array with path=>name pairs but not name=>path because file name can be same for different attachments while sending same file is ridiculous.

avatar Denitz Denitz - open - 1 Mar 2017
avatar joomla-cms-bot joomla-cms-bot - change - 1 Mar 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 1 Mar 2017
avatar mbabker
mbabker - comment - 1 Mar 2017

It doesn't work as an associative array. You have to pass the file path as the first argument and the name as the second, these can either be a single string or an array (and if an array they must both contain the same number of elements).

So...

$mailer = JFactory::getMailer();
$mailer->addAttachment($filepath, $filename);

Or

$mailer = JFactory::getMailer();
$mailer->addAttachment([$filepath], [$filename]);
avatar Denitz
Denitz - comment - 1 Mar 2017

Bad, it limits sending multiple attachments via JFactory::getMailer()->sendMail() shortcut method :(

avatar mbabker
mbabker - comment - 1 Mar 2017

Personal rant, but I honestly dislike half the design of JMail. It break the interface from the class it is inheriting from (PHPMailer) by changing method signatures and what they will and won't accept. If we were decorating the mailer it'd be another story, but as a class extension, we've made some bad design decisions in the past. So I'd actually rather get rid of the array behaviors to be in line with the parent API or refactor JMail to be a decorator around a PHPMailer object.

avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Mar 2017
Category com_mailto
avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2017
Category com_mailto com_mailto Feature Request
avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2017
Priority Medium Low
Status New Discussion
avatar brianteeman brianteeman - change - 25 Mar 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar wilsonge wilsonge - change - 19 Aug 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-08-19 10:46:35
Closed_By wilsonge
avatar wilsonge wilsonge - close - 19 Aug 2018
avatar wilsonge
wilsonge - comment - 19 Aug 2018

I agree it's not the most optimal design but it is there now and would be a b/c break to modify. I've added a commit to improve the documentation around this so it should be clearer what the intention is. Closing.

Add a Comment

Login with GitHub to post a comment