cubiclesoft / jquery-fancyfileuploader

A jQuery plugin to convert the HTML file input type into a fancy file uploader under a MIT or LGPL license. Mobile-friendly too!
58 stars 27 forks source link

Sending email with PHPMailer #3

Closed leelennie closed 6 years ago

leelennie commented 6 years ago

Hi Sir/Mdm,

I'm using phpmailler to send email with attachments. I'm wondering which part should I input the phpmailer code?

I'm trying to understand from Admin Pack (admin.php) but not sure if I'm doing it correctly.

        // ending of file handler code...
        echo json_encode($result, JSON_UNESCAPED_SLASHES);
        exit();
    }

    if (isset($_POST["action"])) {

        $mail = new PHPMailer();
        $mail->setFrom($fromEmail, $fromName);
        $mail->addAddress($sendToEmail, $sendToName); // you can add more addresses by simply adding another line with $mail->addAddress();
        $mail->addReplyTo($from);

        $mail->isHTML(true);

        $mail->Subject = $subject;
        $mail->Body    = $emailTextHtml;
        $mail->msgHTML($emailTextHtml);
        // Attaching files in the mail
        $mail->addAttachment($files);

        // the rest of the code

    }

Or shall I put it inside the

else
{
    // [Do stuff with the file here.]
    // copy($files[0]["file"], __DIR__ . "/images/" . $id . "." . strtolower($files[0]["ext"]));

    // phpmailer code here
cubiclesoft commented 6 years ago

Your second example looks more correct if your intention is to send the uploaded file via e-mail as soon as it is uploaded.

Your first example would be valid if you want to separate the file upload portion from, say, a separate form submission and then bring the separate pieces together when the user submits the form. It's more complicated to do this and might involve using PHP sessions depending on the use-case.

Also worth noting: https://github.com/cubiclesoft/ultimate-email

cubiclesoft commented 6 years ago

Closing issue. Issue trackers are intended for reporting bugs in software. General purpose programming help is better suited to forums, mailing lists, and Stack Exchange.