Good day to all, dear programmers. In the module joomla 3 I try to add to the feedback form a field with the addition of a file. A letter comes, and there is an attachment, but there are solid numbers and letters without an extension and 0kb. Here it is added

<?php $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['uploaded-file']['name'])); $filename = $_FILES['uploaded-file']['name']; if (move_uploaded_file($_FILES['uploaded-file']['tmp_name'], $uploadfile)) { $mail->addAttachment($uploadfile, $filename); } else { $msg .= 'Failed to move file to ' . $uploadfile; } $mailSender->addAttachment($uploadfile); ?> <label> <input class="uploaded-file" id="uploaded-file" type="file" name="uploaded-file"/> <span id="text_fileup">Выбрать файл</span> </label> 

I know something is missing, reviewed a lot, but did not understand what was needed there. Thanks for earlier, who will prompt the right decision. +100,500 in karma to you.😊✌

  • As I understand you are using PHPMailer. It seems everything is according to the documentation, but it is not clear, in one place you have $mail in another $mailSender - Ivan Bolnikh
  • Thank you for responding, there was $ mailSender in the module, it was me who looked at the third-party code in the example. but then I corrected $ mail to $ mailSender, they still do not come with the file .. But later I found the code from this module and now now this: - YurikFirst
  • '$ tmpName = $ _FILES [' attachment '] [' tmp_name ']; $ fileType = $ _FILES ['attachment'] ['type']; $ fileName = $ _FILES ['attachment'] ['name']; $ uploadext = pathinfo ($ fileName, PATHINFO_EXTENSION); $ allowedext = array ('jpg', 'jpeg', 'png', 'pdf'); $ allowedattachment = false; foreach ($ allowedext as $ extension) {if ($ extension == $ uploadext) {$ allowedattachment = true; }} ' - YurikFirst
  • $ mailSender-> setSubject ($ mySubject); $ mailSender-> setBody ($ myMessage); if (move_uploaded_file ($ _ FILES ['attachment'] ['tmp_name'], $ fileName)) {if ($ allowedattachment == true) {$ mailSender-> addAttachment ($ tmpName, $ fileName); } - YurikFirst
  • However, there is still no investment at all - YurikFirst

1 answer 1

Found a solution with similar code on github.com

Thank you very much Stjepan Osojnički.

True, you need to make some settings in the module that would be sent, apparently the module is not added. Namely:

Exact URL - off

Disable HTTPS - on

Fixed URL - off