embedding attachments strings

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Lionel
Forum Newbie
Posts: 7
Joined: Mon May 06, 2002 1:27 am

embedding attachments strings

Post by Lionel »

Hello,

Is it possible to embed an image from database? I just started using this fabulous script, I am able to embed multiple images in my articles, but some of them are binaries from db.

Thank you.
student101
Forum Newbie
Posts: 20
Joined: Sun Sep 21, 2008 4:04 pm

Re: embedding attachments strings

Post by student101 »

This is not a possibility for Swftmail, why? I have attempted my ideas, searched and found nothing! not even basic help.
You can embed it via linking it;

Code: Select all

<html>
<head>
<title>Page title</title>
</head>
<body>
 
<div id="Box">
 
<p>Image name</p>
<div style="height:120px; width:300px;><img src='http://www.example.com/images/imagename.jpg' alt="Alt text" /></div>
 
</div>
OR
<div style="height:120px; width:300px; background:url(http://www.example.com/images/imagename.jpg);"></div>
</body>
</html>
Cheers
If for some reason(that I have not found) there is a way, then someone will post it.
Lionel
Forum Newbie
Posts: 7
Joined: Mon May 06, 2002 1:27 am

Re: embedding attachments strings

Post by Lionel »

That was possible with phpmailer and a hack to embed image from database.
But I must say this Swift script is much more superior.
Only draw back for me is I can embed anything but images from database
student101
Forum Newbie
Posts: 20
Joined: Sun Sep 21, 2008 4:04 pm

Re: embedding attachments strings

Post by student101 »

Lionel wrote:Only draw back for me is I can embed anything but images from database
I don't get what you are saying? You can but you can't?

If you want to send an "embedded" image via any mailer you need the image as a BLOB or the physical path to the image.
There is no possible method that I have found(with Swift or PHPMailer) to send someone an image other than through an attachment!
If you find it - please post it!
Cheers
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: embedding attachments strings

Post by Chris Corbyn »

Just skip the Swift_File class and pass the binary data directly.

Code: Select all

$message->attach(new Swift_Message_Part(
  '<img src="' .
  $message->attach(new Swift_Message_Image($binaryData, 'filename.gif', 'image/gif'))
  . '" />',
  'text/html'
));
student101
Forum Newbie
Posts: 20
Joined: Sun Sep 21, 2008 4:04 pm

Re: embedding attachments strings

Post by student101 »

It can't be that simple?
I have attempted similar but your method makes more sense.

Thank you.

Cheers
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: embedding attachments strings

Post by Chris Corbyn »

I'll be sure to make it more complicated in a future release :P

<side-note>

Actually, in v4 it looks something like this:

Code: Select all

$message->setBody(
  '<img src="' .
  $message->embed(new Swift_Image($binaryData, 'filename.gif', 'image/gif'))
  . '" />',
  'text/html'
);
And for files on disk it looks like this:

Code: Select all

$message->setBody(
  '<img src="' .
  $message->embed(Swift_Image::fromPath('filename.gif'))
  . '" />',
  'text/html'
);
There's a bit less class-clutter coming in v4 (beta coming out any time now).

</side-note>
Post Reply