Home >Backend Development >PHP Tutorial >How to Send File Attachments via Email Using PHP and PHPMailer?
Sending File Attachments from a Form Using PHP and PHPMailer
In your process.php file, you can attach the uploaded file to the email using the following steps:
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) { $uploadInfo = $_FILES['uploaded_file']; }
if (isset($uploadInfo)) { $mail->addAttachment($uploadInfo['tmp_name'], $uploadInfo['name']); }
This code checks if the file was uploaded successfully, then attaches the file to the email using the addAttachment method of PHPMailer. The arguments to addAttachment are the temporary file name of the uploaded file and the original filename, respectively.
Additional Notes:
The above is the detailed content of How to Send File Attachments via Email Using PHP and PHPMailer?. For more information, please follow other related articles on the PHP Chinese website!