0

For some reason, if I use the following code, only one image seems to get sent:

$sql = mysql_query("SELECT photo FROM article_info");
while($row = mysql_fetch_assoc($sql)) {
    $mime->addHTMLImage($row['photo']);
}

But if I were to manually enter each image:

$mime->addHTMLImage("path_to/image1.jpg");
$mime->addHTMLImage("path_to/image2.jpg");

Both images will be sent. Now what's interesting is that with the first piece of code, the image that gets sent though email is image2.jpg. Like if for some reason, $mime gets overwritten, or something. Am I doing something wrong? Why would I only be sending/receiving one image? Any suggestions? Thanks in advance.

cweiske
  • 30,033
  • 14
  • 133
  • 194
thelos999
  • 641
  • 2
  • 7
  • 19

1 Answers1

0

You need to specify the name of the image as third parameter. Currently, the name is empty and thus you overwrite the image-without-a-name with the new image-without-a-name.

http://pear.php.net/manual/en/package.mail.mail-mime.addhtmlimage.php

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • Nope. Still having the same issue. I have it to where it says: $mime->addHTMLImage($row['photo'], 'image/jpg', substr($row['photo'], 7), true); Which should be 'path_to/image1(2).jpg', 'image/jpg', 'image1(2).jpg', true Got no idea what to do... – thelos999 Oct 16 '11 at 18:54
  • 1) the 4th parameter needs to be false. 2) Are you sure that `substr($row['photo'], 7)` is different for the two rows? – cweiske Oct 16 '11 at 18:59
  • Well that sends both attachments, but instead of sending the images, for some reason it sends a text file with the name of the images (image1.jpg and image2.jpg) and within the text file it saved the path and filename (images/image1.jpg)... – thelos999 Oct 16 '11 at 19:35
  • Got it too work. I did a generic search to see if there might be something out there, and decided to try something. I noticed that in some post some people used the file_get_contents() function. So, instead of having the first parameter as $row['photo'], I used file_get_contents($row['photo']) and that seemed to worked. – thelos999 Oct 17 '11 at 00:02