Email Dynamic Image Insert

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kidcobra
Forum Newbie
Posts: 5
Joined: Sun Dec 13, 2009 10:14 am

Email Dynamic Image Insert

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Email Dynamic Image Insert

Post by requinix »

The string is wrapped in single quotes. You can't put variables into those.

Strings
kidcobra
Forum Newbie
Posts: 5
Joined: Sun Dec 13, 2009 10:14 am

Re: Email Dynamic Image Insert

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Email Dynamic Image Insert

Post by requinix »

Code: Select all

$headerPic = "<IMG src='http://sample.com/Sections/uctionItems/photos/$row_rsucites[Image_URL];'>";
kidcobra
Forum Newbie
Posts: 5
Joined: Sun Dec 13, 2009 10:14 am

Re: Email Dynamic Image Insert

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Email Dynamic Image Insert

Post by John Cartwright »

It's an easy concept to understand once you read the link tasairis provided :D
Post Reply