How to send file attachments from form ising phpMailer and PHP?

Spread the love

Sometimes, we want to send file attachments from form ising phpMailer and PHP.

In this article, we’ll look at how to send file attachments from form ising phpMailer and PHP.

How to send file attachments from form ising phpMailer and PHP?

To send file attachments from form ising phpMailer and PHP, we call the AddAttachment method.

For instance, we write

if (
    isset($_FILES["uploaded_file"]) &&
    $_FILES["uploaded_file"]["error"] == UPLOAD_ERR_OK
) {
    $mail->AddAttachment(
        $_FILES["uploaded_file"]["tmp_name"],
        $_FILES["uploaded_file"]["name"]
    );
}

to call $mail->AddAttachment with the temporary name of the file and the real name of the file to add the file at the location as an attachment.

$_FILES["uploaded_file"] has the uploaded file.

Conclusion

To send file attachments from form ising phpMailer and PHP, we call the AddAttachment method.

Leave a Reply

Your email address will not be published.