AesculusMaximus AesculusMaximus - 2 months ago 17
PHP Question

phpmailer file attachment delivered, but downloads a string only

I have a dxf file saved in my

public_html
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:

/home3/frank/public_html/myDxf.dxf


Can anyone see what I am doing wrong?

Answer

Here are two places to start troubleshooting:

1. Attaching of File

Instead of this:

$mail->AddStringAttachment()

try this:

$mail->AddAttachment()

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:

application/pdf

try this:

image/vnd.dxf

List of MIME types: http://www.freeformatter.com/mime-types-list.html

Comments