You will need my TextBetweenArray function to grab all the image links. It has been nice to not have to click "load images" when people receive the newsletter.
Code: Select all
//-----Needed function: TextBetweenArray------
//-----gets all text betwen $s1 and $s2 pairs and puts in an array
function TextBetweenArray($s1,$s2,$s){
$myarray=array();
$s1=strtolower($s1);
$s2=strtolower($s2);
$L1=strlen($s1);
$L2=strlen($s2);
$scheck=strtolower($s);
do{
$pos1 = strpos($scheck,$s1);
if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
$myarray[]=substr($s,$pos1+$L1,$pos2);
$s=substr($s,$pos1+$L1+$pos2+$L2);
$scheck=strtolower($s);
}
}
} while (($pos1!==false)and($pos2!==false));
return $myarray;
}
//-------ATTACH ALL IMAGES-------
//-------$htmlcontent is the message text in HTML format
//-------Images are in an <img> tag using a relative link starting with a '/' such as '/images/myimage.jpg'
$ROOT = $_SERVER['DOCUMENT_ROOT'];
$ImageArray = TextBetweenArray('src="','"',$htmlcontent);
foreach($ImageArray as $image){
$img =& new Swift_Message_Image(new Swift_File("$ROOT$image"));
$src = $message->attach($img);
$htmlcontent = str_replace($image,$src,$htmlcontent);
}