halfasleeps Posted June 20, 2008 Share Posted June 20, 2008 ok i have php page that generates an image called hidalgoImager.php and on another page I want to use PHPMailer to email a copy of the image. the image generating page works but I cant seem to send it in an email. ....is there a way to do this? Any help is apreciated...THANKS!! heres my code on the emailing page: <?php session_start(); $_SESSION["HIDALGO_IMAGE_PIXELS"] = explode("|",$_POST['pixels']); $_SESSION["HIDALGO_IMAGE_WIDTH"] = $_POST['width']; $_SESSION["HIDALGO_IMAGE_HEIGHT"] = $_POST['height']; //print_r($_POST); //echo "<br><br><br>Pixels:<br>".print_r($_SESSION["HIDALGO_IMAGE_PIXELS"]).'<br>'; require_once("../class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsHTML(true); $mail->From = "jisaacks@kranichs.com"; $mail->AddAddress("halfasleeps@gmail.com, jisaacks@kranichs.com"); $mail->Subject = "Hidalgo Image"; $mail->AddEmbeddedImage("hidalgoImager.php", "hidalgo_band", "hidalgo_band.png"); $mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:hidalgo_band"> Here is an image!'; $mail->Send(); echo '<META HTTP-EQUIV="Refresh" CONTENT="0;URL=hidalgo_view_image.php">'; ?> heres my code on hidalgoImager.php: <?php session_start(); function getRGBChannels ($hex) { $difference = 6 - strlen($hex); for($i = 0; $i<$difference; $i++) { $hex = "0".$hex; } $R = substr($hex,0,2); $G = substr($hex,2,2); $B = substr($hex,4,2); // get decimal color values for R G B $R = hexdec($R); $G = hexdec($G); $B = hexdec($B); return array("R" => $R, "G" => $G, "B" => $B); } $pixels = array ("FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000", "FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000"); $x = 4; $y = 4; if(isset($_SESSION["HIDALGO_IMAGE_PIXELS"])){ $pixels = $_SESSION["HIDALGO_IMAGE_PIXELS"]; $x = $_SESSION["HIDALGO_IMAGE_WIDTH"]; $y = $_SESSION["HIDALGO_IMAGE_HEIGHT"]; } $gd = imagecreatetruecolor($x, $y); $pixel = 0; for($i = 0; $i<$y; $i++){ for($j = 0; $j<$x; $j++){ $nextPixel = getRGBChannels($pixels[$pixel]); imagesetpixel($gd, $j,$i, imagecolorallocate($gd, $nextPixel["R"], $nextPixel["G"], $nextPixel["B"]) ); $pixel++; } } header('Content-Type: image/png'); imagepng($gd); ?> Quote Link to comment Share on other sites More sharing options...
halfasleeps Posted June 20, 2008 Author Share Posted June 20, 2008 If this is not possible can someone please offer a solution? Thanks! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 20, 2008 Share Posted June 20, 2008 Well, on the image script, you're sending the output to the browser and not saving the image. If you saved the image, you could e-mail it. Quote Link to comment Share on other sites More sharing options...
halfasleeps Posted June 20, 2008 Author Share Posted June 20, 2008 Thank you very much for your reply. so I do have to save it? thats one thing I was wondering because over time saving all the images could take up alot of server space. maybe there is a way I can save it, then delete it after its done being used? can you please point me to somewhere that will explain how to save/delete the image? Thank you! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 20, 2008 Share Posted June 20, 2008 You can save the image with by adding a filename parameter to the end of the imagepng() call. Look it up in the php manual. You could delete the image after the email script does its thing with unlink(). Quote Link to comment Share on other sites More sharing options...
halfasleeps Posted June 20, 2008 Author Share Posted June 20, 2008 Thank you I will try this out and post back my results. it seems like php.net is down right now? kinda scary. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 20, 2008 Share Posted June 20, 2008 It is. THE WORLD IS ABOUT TO EXPLODE. *Takes cover* =( Quote Link to comment Share on other sites More sharing options...
Barand Posted June 20, 2008 Share Posted June 20, 2008 or email a link to the image and let the recipient save it Quote Link to comment Share on other sites More sharing options...
halfasleeps Posted June 20, 2008 Author Share Posted June 20, 2008 or email a link to the image and let the recipient save it I dont think theres a way to do this because the image being created is based on variables from an application. Basically I have a design your own ring application which is flash, and I want to be able to email them an image of the ring they designs, and be able to use an image of the ring they designed in the shopping cart if they decide to buy it. so after they leave the page, trying to access the script to that generates the image would fail. I think I am good just saving it and then deleting it when I am done. ofcourse I would have to not delete it until they hit the reciept page, so they can see an image of it in their cart. but then I dont know how I would handle deleting it if the user just closes the browser without hitting the receipt page. hmm... I was going to mark this thread resolved but I am not seeing the option. Thanks Guys!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
Barand Posted June 20, 2008 Share Posted June 20, 2008 I always do my dynamic images using query strings to pass the parameters <img src="myimage.php?var1=x&var2=y&var3=z"> If you do it that way it's easy to send the llink. Quote Link to comment Share on other sites More sharing options...
halfasleeps Posted June 22, 2008 Author Share Posted June 22, 2008 I always do my dynamic images using query strings to pass the parameters <img src="myimage.php?var1=x&var2=y&var3=z"> If you do it that way it's easy to send the llink. Unfortuntely the variable I am using is a list of all the pixels for the image which is way to long for a URL query like that. But thats the only way I know of to get the image data from Flash to PHP. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.