Page 1 of 1
Embedding image - same code, different server - doesn't work
Posted: Fri Dec 12, 2008 3:30 pm
by sitho
I used to embed a header image in a newsletter using Swift Mailer. Everything went okay since last week when I changed the webhosting partner. The whole stuff were transported to the new server, _no code has been changed_, just a copy from one server to another.
Now the image doesn't show up in the letter, its place is the well known X-sign when the browser (or the mail client) doesn't find the image. But the image itself shows up as a regular attachment to the email.
What can I do? Please, anyone who has an idea, write down here, I'll try it. Thanks!
Re: Embedding image - same code, different server - doesn't work
Posted: Fri Dec 12, 2008 5:18 pm
by Chris Corbyn
Code please
How are you embedding the image?
Re: Embedding image - same code, different server - doesn't work
Posted: Sat Dec 13, 2008 7:53 am
by sitho
Code: Select all
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/NativeMail.php";
$swift =& new Swift(new Swift_Connection_NativeMail());
$message =& new Swift_Message($mysubject);
$img =& new Swift_Message_Image(new Swift_File("/var/www/domain.com/images/newsletter-header.jpg"));
$src = $message->attach($img);
and then
Code: Select all
$message->attach(new Swift_Message_Part("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
...blablabla...
<td style=\"height: 91px;\"><img src=\"". $src ."\" /></td>
...blablabla...
This used to perfectly work up til now, but on the new server it doesn't. The newsletter itself goes out properly throwing no errors. The annoying thing is the image isn't really embedded, it shows up as a regular attachment.
Re: Embedding image - same code, different server - doesn't work
Posted: Sat Dec 13, 2008 8:05 am
by sitho
The result is, in the final email:
Code: Select all
<img src="cid:swift-12291230454942ede5a8c2c..0@www.domain.com" />
I noticed a little difference, in the mail bodies earlier this figured stg like this:
Code: Select all
<img src="cid:swift-12291230454942ede5a8c2c.0@www.domain.com" />
The difference is that now it has two dots before the null character, while earlier it had just one dot. I don't know if it makes sence... If yes, what and why does that?

Re: Embedding image - same code, different server - doesn't work
Posted: Sat Dec 13, 2008 6:32 pm
by Chris Corbyn
Hmm, that's odd. Looks like this code in Swift/Message/Attachment.php isn't working for you.
Code: Select all
/**
* Get a unique filename (just a sequence)
* @param string the prefix for the filename
* @return string
*/
public static function generateFileName($prefix="file")
{
return $prefix . (self::$fileId++);
}
Specifically, the "(self::$fileId++)" bit is evaluating to an empty string.
I'll it's hard to be sure but it appears that this is the cause. If that is the cause version 4 will resolve this since it doesn't increment a sequence it produces a CID based on a specification.
Re: Embedding image - same code, different server - doesn't work
Posted: Mon Dec 15, 2008 4:43 am
by sitho
I may use version 4, because I found that function in my codes and it looks like this:
Code: Select all
function generateFileName($prefix="file")
{
static $id = 0;
return $prefix . ($id++);
}
Do you suggest me to try v5 instead in this case?
Re: Embedding image - same code, different server - doesn't work
Posted: Mon Dec 15, 2008 6:37 am
by Chris Corbyn
It looks like you're using a PHP 4 version of Swift Mailer. Try downloading the PHP 5 version assuming your server is running PHP 5
NOTE: Support for PHP 4 has officially ended
Re: Embedding image - same code, different server - doesn't work
Posted: Sat Jan 03, 2009 11:42 am
by sitho
I switched to version 5, and it works good again!

Thanks for the tip!
Happy new year, btw...
