What is the difference between AddStringAttachment() and AddAttachment() in PHPMailer?

AddStringAttachment() is used to attach a file by providing the file contents as a string, while AddAttachment() is used to attach a file by providing the file path on the server. If you have the file contents as a string, you should use AddStringAttachment(), and if you have the file stored on the server, you should use AddAttachment().

// Using AddStringAttachment() to attach a file by providing the file contents as a string
$fileContents = 'This is the content of the file';
$filename = 'example.txt';
$mail->AddStringAttachment($fileContents, $filename);

// Using AddAttachment() to attach a file by providing the file path on the server
$filePath = '/path/to/file/example.pdf';
$mail->AddAttachment($filePath);