here are the code
Code: Select all
<?
//set timeout to never timeout
set_time_limit(1000);
$unsubscribe_link = "http://mycompany/unsubscribe.php";
//$unsubscribe_link = "http://mycompany/unsubscribe.php";
include("../connect.php");
function getFilename($str){
$arr = explode("/",$str);
return $arr[count($arr)-1];
}
function breakHTML($str){
$new_str="";
$inTag = false;
$cnt=0;
for ($i=0;$i<strlen($str);$i++)
{
if ($str[$i]=="<" && $str[$i+1] != " ")
$inTag = true;
if ($str[$i]==">" && $inTag)
$inTag = false;
if ($cnt>=70 && !$inTag && ($str[$i+1]==" " || $str[$i+1]=="<"))
{
$new_str.="$str[$i]\r\n";
$cnt=0;
}
else
$new_str.="$str[$i]";
$cnt++;
}
return $new_str;
}
//getImages parse html code and returns a list of images in an array
//the last element in the array contains the html img-tags ready for e-mail
function getImages($text){
$params="";
$arr=explode("<img ",$text); //break the html up in smaller pieces
for ($i=1;$i<count($arr);$i++){ //start at the 2nd piece and loop through the pieces
$arr2 = explode("src=\"",$arr[$i]);
$imgsrc=$arr2[1];
$pos = strpos($imgsrc,"\""); //get the position of the "
$theString=substr($imgsrc,0,$pos); //get the string between src=" and "
//print "$theString<br><br>";
$text=str_replace("$theString","cid:".getFilename($theString),$text);//replace all these ocurrences with the text we want
$params[]=getFilename($theString); //add to array
}
$params[]=$text; //add the email-ready-html-code to the end of the array
return $params; //return the array
}
function fix_eq($txt){
return str_replace("=\"","=3D\"",$txt);
}
//site files on
$site = dirname($_SERVER["SCRIPT_FILENAME"]);
$site1 = substr($site,0,strrpos($site,"/"));
//loop around lists
$sql="select * from lists order by name";
$listres=query($sql);
$numrows1=numrows($listres);
$line1=0;
$recipients="";
while ($line1 < $numrows1)
{
$displist=getArray($listres,$line1);
$listvar="list$displist[record]";
$listval=$$listvar;
if ($listval=="Y")
{
//loop around email addresses in this list
$sql="select email from addresses where listid=$displist[record] and active='1'";
$addressres=query($sql);
$numrows2=numrows($addressres);
if ($numrows2 > 0)
{
$line2=0;
while ($line2 < $numrows2)
{
$dispaddress=getArray($addressres,$line2);
$recipients[]="$dispaddress[email]";
$line2++;
}
}
}
$line1++;
}
//draw up the email in html format
$msg ="<html>\r\n";
$msg.="<body>\r\n";
$msg.="<table width=3D\"63\" border=3D\"0\" align=3D\"center\" cellpadding=3D\"1\" cellspacing=3D\"0\">\r\n";
$msg.="<tr>\r\n";
$msg.="<td bgcolor=3D\"#336666\"><table width=3D\"42%\" border=3D\"0\" cellspacing=3D\"0\" cellpadding=3D\"0\">\r\n";
$msg.="<tr>\r\n";
$msg.="<td><img name=3D\"newsletter0\" src=3D\"cid:newsletter1.jpg\" width=3D\"241\" height=3D\"95\" border=3D\"0\" alt=3D\"\" /><img name=3D\"newsletter1\" src=3D\"cid:newsletter2.jpg\" width=3D\"273\" height=3D\"95\" border=3D\"0\" alt=3D\"\" /><img name=3D\"newsletter2\" src=3D\"cid:newsletter3.jpg\" width=3D\"266\" height=3D\"95\" border=3D\"0\" alt=3D\"\" /></td>\r\n";
$msg.="</tr>\r\n";
$msg.="<tr>\r\n";
$msg.="<td valign=3D\"top\" background=3D\"cid:newsletter4.jpg\"><p><img name=3D\"newsletter3\" src=3D\"cid:newsletter4.jpg\" width=3D\"780\" height=3D\"3\" border=3D\"0\" alt=3D\"\" /></p>\r\n";
$msg.="<table width=3D\"100%\" border=3D\"0\" cellspacing=3D\"0\" cellpadding=3D\"10\">\r\n";
$msg.="<tr>\r\n";
$msg.="<td>\r\n";
$msg.="<TABLE WIDTH=3D\"750\">\r\n";
$news_rs = query("select * from newsletter where record=$newsletterid");
if (numrows($news_rs) > 0) {
$news_ds = getArray($news_rs,0);
$msg .= "<tr><td><font color=3D\"#CCCCCC\" size=3D\"2\" face=3D\"Arial, Helvetica, sans-serif\"><b>$news_ds[title]</b> - ".date("d-m-Y",$news_ds[date])."</font></td></tr>\r\n";
$params=getImages($news_ds[article]);
$html = $params[count($params)-1];
$html=fix_eq($html);
//$html=str_replace(">",">\n",$html);
$html=breakHTML($html);
$new_mess = $html;
$msg .= "<tr><td>$new_mess</td></tr>\r\n";
}
$msg.="<tr><td><a href=3D\"$unsubscribe_link\">Click here to unsubscribe.</a></td></tr>\r\n";
$msg.="</table>\r\n";
$msg.="</td>\r\n";
$msg.="</tr>\r\n";
$msg.="</table>\r\n";
$msg.="</td>\r\n";
$msg.="</tr>\r\n";
$msg.="<tr>\r\n";
$msg.="<td><img name=3D\"newsletter5\" src=3D\"cid:newsletter6.jpg\" width=3D\"241\" height=3D\"88\" border=3D\"0\" alt=3D\"\" /><img name=3D\"newsletter6\" src=3D\"cid:newsletter7.jpg\" width=3D\"273\" height=3D\"88\" border=3D\"0\" alt=3D\"\" /><img name=3D\"newsletter7\" src=3D\"cid:newsletter8.jpg\" width=3D\"266\" height=3D\"88\" border=3D\"0\" alt=3D\"\" /></td>\r\n";
$msg.="</tr>\r\n";
$msg.="</table></td>\r\n";
$msg.="</tr>\r\n";
$msg.="</table>\r\n";
$msg.="</body>\r\n";
$msg.="</html>\r\n";
//generate a boundary
$boundary=strtoupper(md5(uniqid(time())));
//generate another boundary
$boundary2=strtoupper(md5(uniqid(time()+3000)));
$headers = "From:<info@dlink.co.za>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related;\n\tboundary=\"$boundary\"\n";
$body = "This is a multi-part message in MIME format.\n\n";
$body .= "--$boundary\n";
$body .= "Content-Type: multipart/alternative;\n\tboundary=\"$boundary2\"\n\n";
$body .= "--$boundary2\n";
$body .= "Content-Type: text/plain;\n\tcharset=\"utf-8\"\n";
$body .= "Content-Transfer-Encoding: quoted-printable\n\n";
$body .= "--$boundary2\n";
$body .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$body .= "Content-Transfer-Encoding: quoted-printable\n\n";
//where text should go
$body .= $msg;
$body .= "\n\n--$boundary2--";
//this function attaches images to the email
function attach($subdir,$filename)
{
global $boundary;
global $site;
if (strstr($filename,"jp"))
$type="image/jpeg";
if (strstr($filename,"gif"))
$type="image/gif";
//open file for reading
if ($subdir == "pics") $file="$subdir/$filename";
else $file = "$subdir/$filename";
//die($file);
$fp=fopen($file,"r");
$filesize=filesize($file);
//read contents of file into a variable
$contents=fread($fp,$filesize);
//close file
fclose($fp);
//encode the file
$attachment=chunk_split(base64_encode($contents));
$att .= "\n\n--$boundary\n";
$att .= "Content-Type: $type;\n\tname=\"$file\"\n";
$att .= "Content-Transfer-Encoding: base64\n";
$att .= "Content-Disposition: inline; filename=\"$filename\"\n";
$att .= "Content-ID: <$filename>";
$att .= "\n\n$attachment";
return $att;
}
//attach pics
$body.=attach("pics","newsletter1.jpg");
$body.=attach("pics","newsletter2.jpg");
$body.=attach("pics","newsletter3.jpg");
$body.=attach("pics","newsletter4.jpg");
// $body.=attach("pics","newsletter5.jpg");
$body.=attach("pics","newsletter6.jpg");
$body.=attach("pics","newsletter7.jpg");
$body.=attach("pics","newsletter8.jpg");
//loop around the other images
for ($a=0;$a<(count($params)-1);$a++)
$body.=attach("images",$params[$a]);
//final email boundary
$body .= "\n\n--$boundary--";
$numaddresses=count($recipients);
$nummails=ceil($numaddresses/200);
//loop around number of emails
for ($a=1;$a<=$nummails;$a++)
{
$addresses="";
$start=($a-1)*200;
$end=$start+200;
if ($end > $numaddresses)
$end=$numaddresses;
//take 200 addresses at a time
for ($b=$start;$b<$end;$b++)
{
//get rid of last comma at end of each list
$len=strlen($recipients[$a]);
$addresses.="$recipients[$b],";
}
//get rid of last comma
$len=strlen($addresses);
$addresses=substr($addresses,0,$len-1);
$theseheaders=$headers . "bcc: $addresses";
mail("",$subject,$body,$theseheaders);
}
closeDB();
print "<script language='javascript'>alert('The email has been successfully emailed to the mailing list!');";
print "location.href='news_admin.php';</script>";
?>Every time I sent the email all I get is the text and not the pictures if I have alook @ the source it says cid:newsletter1.jpg
what and I doing wrong can you please help.
Code: Select all
Code: Select all