AesculusMaximus AesculusMaximus - 1 year ago 76
PHP Question

phpmailer file attachment delivered, but downloads a string only

I have a dxf file saved in my

folder on my server. I would like to add this as an attachment to an email. I apply the following code line:

$mail->AddStringAttachment($_SERVER['DOCUMENT_ROOT'] . '/myDxf.dxf', 'myFile.dxf', 'base64', 'application/pdf');

This attaches a dxf and the email is sent. However, when I download the attachment, instead of being a true dxf, it just has a string inside with the file path:


Can anyone see what I am doing wrong?

Answer Source

Here are two places to start troubleshooting:

1. Attaching of File

Instead of this:


try this:


File Attachments

The command to attach a local file is simply $mail->addAttachment($path);, where $path contains the path to the file you want to send, and can be placed anywhere between $mail = new PHPMailer; and sending the message. Note that you cannot use a URL for the path - you may only use local filesystem path.

If you want to send content from a database or web API (e.g. a remote PDF generator), do not use this method - use addStringAttachment instead.

2. MIME type

Instead of this:


try this:


List of MIME types:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download