$mailer = JFactory::getMailer();
$app = JFactory::getApplication();
$email = 'your@email'; // replace this with an actual email
$mailer->sendMail($app->get('mailfrom'), $app->get('fromname'), $email, 'Test mail', '<p>This is a <strong>test</strong> message</p>', true, null, null, JPATH_SITE . '/images/joomla_black.png');
An HTML formatted email with an image attachment.
This is a test message
[image]
The result is that the email is missing the "Content-Type", the "From" you've specified, "MIME-Version", "Date" and thus treated as plain text. The boundaries and the encoded file contents show up in the message.
This is a multi-part message in MIME format.
--b1_43f3380ed0c3e4478bc52721618a6943
Content-Type: text/html; charset=us-ascii
<p>This is a <strong>test</strong> message</p>
--b1_43f3380ed0c3e4478bc52721618a6943
Content-Type: application/octet-stream; name="joomla_black.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=joomla_black.png
[base64 encoded text]
PHP 8
Joomla! 3.9.25
I've been scratching my head the past day to find out what causes this and noticed this in PHP mail():
Multiple extra headers should be separated with a CRLF (\r\n)
It seems PHPMailer separates them by \n
and PHP treates them as a single header. Most likely the PHPMailer class needs to be updated so that Joomla! 3 can support PHP 8. To fix this I've modified the mailPassthru() function in libraries/vendor/phpmailer/class.phpmailer.php
:
$header = str_replace("\n", "\r\n", $header);
Basically the $additional_headers
param from mail() will now receive the headers separated as CRLF and the email will be sent correctly. Not sure if this has any other implications though.
Labels |
Added:
?
|
Ah and did you checked whether that works on php lower than 8 too? Or do we need to do a version conditional?
Just tested this with PHP 7.3.27 and both \n
and \r\n
seem to work correctly.
can someone remember me why we need a backport and not using the last one ?
https://github.com/PHPMailer/PHPMailer/releases/tag/v6.3.0
It's probably because it requires PHP 5.5+ and Joomla! 3 still supports 5.3.10
This is exactly the kind of institutional knowledge that should be documented somewhere so that it is not lost and can be referred to.
This was fixed upstream in PHPMailer/PHPMailer#2188 and I have made a PR to merge that same change in the Joomla force of phpMailer here: joomla-backports/PHPMailer#1 please test that and report back on that PR. This can then get closed.
@OctavianC Please test joomla-backports/PHPMailer#3
I could never replicate the problem, but I dont seem to make it worse with the proposed fix, which is similar to the upstream fix, but because of the change in major version is harder to apply I applied a light touch
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-03-30 21:15:37 |
Closed_By | ⇒ | zero-24 |
Yes thats right the plan is to point our conposer.json to the backports repo and than pull the changes from there into the CMS.
my point, badly made, was that maybe its worth keeping this issue open until those additional tasks have taken place so it doest get lost.
Also as far as I know my changes were not tested by anyone other than myself... do you really trust me that well.. I dont :)
Status | Closed | ⇒ | New |
Closed_Date | 2021-03-30 21:15:37 | ⇒ | |
Closed_By | zero-24 | ⇒ |
Ah reopend that Issue here until the PR against the CMS is made.
Well, there's one more person who tested this - I just got caught up with other issues and totally forgot to reply.
Server information, if it makes any difference:
php: Linux server6.ghesi.net 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
dbserver: mysql
dbversion: 5.5.5-10.2.37-MariaDB-cll-lve
dbcollation: utf8mb4_general_ci
dbconnectioncollation: utf8mb4_general_ci
phpversion: 8.0.3
server: LiteSpeed
sapi_name: litespeed
version: Joomla! 3.9.25 Stable [ Amani ] 02-March-2021 15:00 GMT
platform: Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
useragent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0
I can easily reproduce this bug with any shared hosting (linux + PHP8) that can send mail using PHP's mail() function. Not sure about your Mac setup since I'm not familiar with that @PhilETaylor
Pleased it worked for you. I thought it would work as its the same fix that the PHPMailer project used.
The credit for the actual fix was with the upstream project, as they had already done the hard work, all I did was find a way to merge it into the older version of PHPMailer.
Ah reopend that Issue here until the PR against the CMS is made.
@zero-24 Is a release going to be made here? https://github.com/joomla-backports/PHPMailer/releases or are we going to target a commit (bad) in the composer.json?
IIRC with lessphp we used the branch but i agree that doing an propper release would be better. We would have to take a look what makes the most sense in our case.
Please, Who do I need to ask "nicely" to make a release so that we can make progress on this please?
Yup
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-05-19 06:22:44 |
Closed_By | ⇒ | alikon |
We have to do changes to phpmailer ourself anyway as our version is out of support so can you please send a PR against: https://github.com/joomla-backports/PHPMailer
After thats merged there we have to do a release and update composer to point to our fork.