Page 1 of 1

missing images with file embedding plugin

Posted: Fri Jun 22, 2007 5:57 am
by garethjax
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello again 

This time my images are misteriously disappearing during the process.

This is my test email (of course there is a "1.jpg" image inside my test folder.

[syntax="html"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<img src="1.jpg" width="670" height="231" />
</body>
</html>
And this is my php code.[/syntax]

Code: Select all

<?php

 
//----------------------------------------------
//DEFINIZIONI INIZIALI

$from = "info-easynet@skf.it"; //mittente email
$nominativo = "name"; //nominativo del mittente, appare nel FROM:
$oggetto = "subject"; //oggetto


//----------------------------------------------

error_reporting(E_ALL);
ini_set("display_errors", "On");

//load address from external file
$filename = "indirizzi.txt";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);

echo "contenuti:".$contents;

$indirizzi = explode("\n", $contents);

//load newsletter from file
$filename = "newsletter.html";
$handle = fopen($filename, "rb");
$newsletter = fread($handle, filesize($filename));
fclose($handle);

//text only version newsletter
$filename = "newsletter.txt";
$handle = fopen($filename, "rb");
$textonly = fread($handle, filesize($filename));
fclose($handle);

// single quota replacer
$newsletter= str_replace(chr(39), chr(146) , $newsletter);


require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/Throttler.php";
require_once "lib/Swift/Plugin/FileEmbedder.php";
//Attach the plugin

 
$smtp =& new Swift_Connection_SMTP("my own mail server", 25);
 
$swift =& new Swift($smtp);
$swift->log->enable();
 
//Attach the plugin
$swift->attachPlugin(new Swift_Plugin_FileEmbedder(), "file_embedder");
$throttler =& new Swift_Plugin_Throttler();
$throttler->setEmailsPerMinute(100); //Max of 1 email every 2 seconds

 
$message =& new Swift_Message($oggetto);

$message->attach(new Swift_Message_Part($newsletter, 'text/html'));

$recipients =& new Swift_RecipientList();


foreach ($indirizzi as $value) {
	$recipients->addTo($value); //or we can just add the address
    //echo "-".$value."<br>";
	echo "<pre>indirizzo:".$value."</pre>";
}



 
 // formato dell'invio: corpo del messaggio, lista dei destinatari, indirizzo e nome del mittente.
$swift->batchSend($message, $recipients, new Swift_Address($from,$nominativo));

//recommended to do this
$swift->disconnect();

?>
Any idea ? :cry:


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jun 22, 2007 9:52 am
by garethjax
update and workaround: it seems a problem due to the local path. I've linked them from a local webserver, and swiftmailer was able to load and embed my image.

Posted: Fri Jun 22, 2007 11:05 am
by Chris Corbyn
garethjax wrote:update and workaround: it seems a problem due to the local path. I've linked them from a local webserver, and swiftmailer was able to load and embed my image.
Thanks, that will be a bug with my regex then :twisted:

Posted: Thu Jun 28, 2007 4:44 am
by garethjax
d11wtq wrote:
garethjax wrote:update and workaround: it seems a problem due to the local path. I've linked them from a local webserver, and swiftmailer was able to load and embed my image.
Thanks, that will be a bug with my regex then :twisted:
I've also noticed that the file embedder cannot embed the background images in the <table> or <td> tag.

I've tried adding them with a code like this, but they are not working.:cry:

Code: Select all

$plugin =& new Swift_Plugin_FileEmbedder();
				$plugin->setTagDefinition("table", "background", array("jpg", "png"));
				$plugin->setTagDefinition("td", "background", array("jpg", "png"));
				 
		
				$swift->attachPlugin(new Swift_Plugin_FileEmbedder(), "file_embedder");

Posted: Thu Jun 28, 2007 3:04 pm
by Chris Corbyn
You're passing a "new" instance of the plugin to swift so your defaults are irrelevant:

Code: Select all

$plugin =& new Swift_Plugin_FileEmbedder(); 
                                $plugin->setTagDefinition("table", "background", array("jpg", "png")); 
                                $plugin->setTagDefinition("td", "background", array("jpg", "png")); 
                                 
                
                                $swift->attachPlugin($plugin, "file_embedder");