Embedding Images

Question: I need an example/instruction of using the script to embed images similar to the one sent with the free version of your script.

Answer: Note that this question and answer refer specifically to the "Ask Felgall" advanced email script and other email scripts that allow you to embed images would use different methods.

To attach the images to be embeded you set up a field on your email form called "embed". This can be a hidden field if you don't want to give your visitors the opportunity to embed images from their own computer. Alternatively use a hidden field to "include" a separate php file and assign a value to $embed in there. If you want to combine images selected by your visitor from their computer with images you select from your site into the same email then you will need to use an include file to contain the code to combine them.

The value assigned to the embed field or $embed variable is a comma separated list of the images that you want to embed into the email. For example if you have two images in the images directory of your web site called img1.jpg and img2.gif then the value that you need would be "images/img1.jpg,images/img2.gif".

The above coding gets the images embedded into the email (provided that they are actually referenced from the email content). The next step is to provide that reference by telling the email where to display them in the html version of the email. To do this you first need to set the email to html format by either having a hidden "fmt" field with a value of "html" or you assign it to $fmt in your include file.

Finally in the template hidden field or $template in your include file you specify where the images are to appear using ~embed0~ and ~embed1~ (and so on if you have more than two images). I suggest you to use the include file rather than a hidden field so as to avoid getting the html content of your template field misinterpreted by the browser.

The following is part of the content of the include file that I used with that form that shows how the two images I used there are embedded:

// first few lines defining replyemail, subject, and url omitted
$fmt = "html";
$header = "<html><head><title>Sample Email</title></head><body bgcolor=\"#ffffff\">";
$footer = "</body></html>";
$template = "<p align=\"center\">~embed0~</p>"; // this embeds img/head.gif
$template .= "<p>This is a - one off - sample email generated by the advanced email to form php script available from the <a href=\"http://www.felgall.com/\">Ask Felgall</a> website.</p>";
// section of template definition that doesn't contain images omitted
$template .= "<p align=\"center\"><a href=\"http://www.felgall.com/\">~embed1~</a></p>"; // this embeds img/built.gif
$attach = "inc/email.zip";
$embed = "img/head.gif,img/built.gif";

Note that this example uses statically defined images that are available on the website (in this case in the img sub-directory).


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow