I'm looking for a solution to allow to add attachments to a contact us form. I tried this module https://github.com/vijayrami/Magelearn_ContactAttachment but it doesn't work well. PDF is not being sent and you can only attach one file.

Are there any good solutions for that? I haven't found anything, even paid.

Also, it would be then connected to a Vue Storefront but this is another question.

It's Magento 2.4.1.



PHP Mailer for sending mail as Magento uses the PHP mail() method by default, although there are extensions that can be installed to override this behaviour. To send email from Magento you need to configure an email SMTP server on the web host/server. You need to configure PHP-Mailer via PHP ini configuration file with the mail function, to provide correct sendmail, or an correct hostname, etc. For file attachment


The above method creates a file in the uploads/ directory with the name of the file as it was named on the up-loader laptop. After then use this sample code to add the attachment to phpMailer so you are basically attempting to attach a file. Code


HTML file

    <input id="file" name="file" type="file" />


    $email = $_REQUEST['email'] ;
    require("phpmailer/PHPMailerAutoload.php");//adding a file
    $mail = new PHPMailer();
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPAuth = true; 
    $mail->Username = "yoursmtp@username.com"; // SMTP username
    $mail->Password = "hidden"; // SMTP password
    $mail->From = $email;
    $mail->SMTPSecure = 'tls'; 
    $mail->Port = 587; //SMTP port
    $mail->addAddress("your@email.com", "your name");
    $mail->Subject = "You have an email from a website visitor!";
    $mail->Body ="
    Name: $name
    Comments: $message";
    echo "Message could not be sent. <p>";
    echo "Mailer Error: ";
    echo "<script>alert('Message has been sent')</script>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.