Page 1 of 1

Email Dynamic Image Insert

Posted: Sun Dec 13, 2009 10:23 am
by kidcobra
HI. The following code from the beginning of an html email works in a dynamically generated email to insert a fixed image. When I replace the end of the image URL string to try and make it a dynamic image based on the recipent, I cannot get it to work. My replacement string is at the end of the working (fixed image) code. Can anyone tell me what I am missing (probably a lot:) Many thanks in advance for any help.

Code: Select all

<?php
$id = $row_rsucites['Item_Num'];
$to = $row_rsucites['Email1'] . " , ";
$to .= $row_rsucites['Email2'] . " , ";
$to .= $row_rsucites['Email3'];
$subject = "Sample Subject";
$headerPic = '<IMG src="http://sample.com/Sections/uctionItems/photos/photo.jpg">';
$body = "<html><body>" .
    "<h2><center>With Compliments: From Sample.com!<br><br>
        Sample Text!</center></h2>" .
 
        "<p><center>$headerPic</center></p>" .
 
My attempt at dynamic image by replacing the $headerPic line photo.jpg at the end with dynamic bla bla is:

Code: Select all

$headerPic = '<IMG src="http://sample.com/Sections/uctionItems/photos/$row_rsucites['Image_URL'];">';
 
where the dbase field Image_URL holds .jpg photo names which are stored in the folder photos.

Any help would be greatly appreciated!

Re: Email Dynamic Image Insert

Posted: Sun Dec 13, 2009 3:37 pm
by requinix
The string is wrapped in single quotes. You can't put variables into those.

Strings

Re: Email Dynamic Image Insert

Posted: Sun Dec 13, 2009 5:29 pm
by kidcobra
Hi tasairis, and thanks for pointing that out. Anyway, I tried it 20 different ways without the single quotes (double, none, etc) and cannot get it working. If you have any more thoughts about any other screw ups in the code, please let me know. And either way, thanks again for help. It's greatly appreciated.

Re: Email Dynamic Image Insert

Posted: Sun Dec 13, 2009 6:05 pm
by requinix

Code: Select all

$headerPic = "<IMG src='http://sample.com/Sections/uctionItems/photos/$row_rsucites[Image_URL];'>";

Re: Email Dynamic Image Insert

Posted: Mon Dec 14, 2009 2:15 am
by kidcobra
HI Tasairis! Thanks for the corrections. I obviously was not going to get this working no matter how many hours I spent, and your line of code finally solved it for me. I had to take out the semi colon after [Image_URL] in order to get to work (it was printing that semi colon in the source code of the email at the end of the path to the image, which resulted in access to an error page and not the image), but without your corrections and suggestions, I would not have gotten it. I really appreciate it. Thanks again, Greg

Re: Email Dynamic Image Insert

Posted: Mon Dec 14, 2009 2:29 am
by John Cartwright
It's an easy concept to understand once you read the link tasairis provided :D