0

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.

Thanks!

0

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

    move_uploaded_file($file_tmp,"uploads/".$file_name);

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

    $mail->addAttachment("uploads/".$file_name);

HTML file

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

Code

    <?php
    $email = $_REQUEST['email'] ;
    require("phpmailer/PHPMailerAutoload.php");//adding a file
    $mail = new PHPMailer();
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPAuth = true; 
    $mail->IsSMTP();
    $mail->Username = "yoursmtp@username.com"; // SMTP username
    $mail->Password = "hidden"; // SMTP password
    $mail->addAttachment("uploads/".$file_name);
    $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";
    if(!$mail->Send())
    {
    echo "Message could not be sent. <p>";
    echo "Mailer Error: ";
    exit;
    }
    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.