What are common reasons for the "No such file or directory" error when trying to send an attachment in PHP?

The "No such file or directory" error in PHP when trying to send an attachment typically occurs when the file path specified is incorrect or the file does not exist. To solve this issue, double-check the file path and ensure that the file exists in the specified location.

$file_path = '/path/to/attachment/file.txt';

if (file_exists($file_path)) {
    // Code to send email with attachment
} else {
    echo 'File does not exist';
}