clarkk
clarkk

Reputation: 1

phpmailer attach file

How to send a file as string with phpmailer?

The file contents is stored in Mysql as a BLOB, but when sending the mail the filesize is only 2 bytes? In the database the size is about 30kb?

$phpmailer->AddStringAttachment(
  base64_encode($row['file_data']),
  $row['file_name'],
  'base64',
  $row['file_type']
);

The data is fetched directly from the mysql database without any processing...

This will display the image in the browser

header('Content-type: '.$row['file_type']);
echo $row['file_data'];

Upvotes: 0

Views: 854

Answers (1)

Spudley
Spudley

Reputation: 168853

Firstly, I imagine you probably meant base64_encode() rather than decode?

However, my guess is that you probably don't want to be encoding it at all -- phpMailer handles the encoding internally for you, so you shouldn't need to do any base64 encoding yourself.

So I think the correct answer is simply to pass the data to the mailer without doing any encoding at all.

$phpmailer->AddStringAttachment(
  $row['file_data'],
  $row['file_name'],
  'base64',
  $row['file_type']
);

Hope that helps.

Upvotes: 1

Related Questions