9951 explained code solutions for 126 technologies


phpmailerHow do I add a file to PHPMailer?


To add a file to PHPMailer, use the addAttachment() method. This method takes two parameters: the file path and the file name.

$mail->addAttachment('/path/to/file.pdf', 'file.pdf');

The output of this code will be true, indicating that the file was successfully attached.

Code explanation

  • addAttachment(): The method used to add a file to PHPMailer.
  • '/path/to/file.pdf': The file path.
  • 'file.pdf': The file name.

Helpful links

Edit this code on GitHub