Embedding image - same code, different server - doesn't work

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
sitho
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2008 3:11 pm

Embedding image - same code, different server - doesn't work

Post 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!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Embedding image - same code, different server - doesn't work

Post by Chris Corbyn »

Code please ;)

How are you embedding the image?
sitho
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2008 3:11 pm

Re: Embedding image - same code, different server - doesn't work

Post 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.
sitho
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2008 3:11 pm

Re: Embedding image - same code, different server - doesn't work

Post 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? :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Embedding image - same code, different server - doesn't work

Post 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.
sitho
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2008 3:11 pm

Re: Embedding image - same code, different server - doesn't work

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Embedding image - same code, different server - doesn't work

Post 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
sitho
Forum Newbie
Posts: 5
Joined: Fri Dec 12, 2008 3:11 pm

Re: Embedding image - same code, different server - doesn't work

Post by sitho »

I switched to version 5, and it works good again! :D Thanks for the tip! :bow:

Happy new year, btw... :drunk:
Post Reply