How can the correct file extension be included when sending email attachments in PHP?
When sending email attachments in PHP, it is important to include the correct file extension in the attachment name to ensure that the recipient can easily identify and open the file. This can be achieved by extracting the file extension from the original file name and appending it to the attachment name before sending the email.
// Original file name
$originalFileName = "example.pdf";
// Extract file extension
$fileExtension = pathinfo($originalFileName, PATHINFO_EXTENSION);
// Attachment name with correct file extension
$attachmentName = "attachment." . $fileExtension;
// Attach the file to the email
$mail->addAttachment($originalFileName, $attachmentName);