Display images from server in email

kevin wood 1 Tallied Votes 193 Views Share

This code will display images within an email from the server. It will display an image with a choice of file extension which can be expanded to fit your needs.

this code was originally developed for a emailing system where the images to be displayed where uploaded by the user.

LastMitch commented: Thanks for sharing! +12
$image = "";
$broad_img1= "";
//this has to be set like this as if file exist does not work with absolute paths
$path= 'http://wwwyour web site.com';
//this is the directory where the images are stored
$web_image_folder = 'image/thumbs';
$exts = array('jpg', 'png', 'gif', 'jpeg');
//the name of the file on the server
$image_name = 'thumb_image1';


// check for each extension
foreach($exts as $ext) {
   if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) {
     $image = $image_name.'.'.$ext;
   }
}

// check if we have an image
if ($image != "") {
    // ok we have the image now store it in a variable
    $broad_img1='<img src="' . $path."/".$web_image_folder."/".$image . '" />';
} else {
    // error, we can't find the image.
}
Member Avatar for LastMitch
LastMitch

This code will display images within an email from the server. It will display an image with a choice of file extension which can be expanded to fit your needs.

It's a bit of a challenge to display an image within an email without additional code (email). Overall, it was good. Thanks for sharing.

But it does work (without the email) and it does display the the image:

2ce9b3a9f054fa781c8be9df5e42ea00

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.