php - PHPMailer how to add embedded image inside foreach loop

781

PHPmailer will not let me add an embedded image inside a foreach loop the path is correct but for some reason it is not adding the image i have checked other sorces on here but with no luck the images are embedding fine when out of the loop but it is just when i call them by using variable names eg the way i need to inside a for each loop as the images will be dynamic it will not embed any help appreciated.

The path looks all good but it just will not run in the loop? Please let me know if you need to see any more code i just did not want to include irrelevant code as i know the message is already sending fine it is just this bit that i have a problem with. I have the table working in html that is not being sent via email if that is of any use outputting the images correctly in the foreach loop

<tbody>'.
    '<span class="page_speed_630936170">'. $i = 1;' .</span>'.

         $total_quantity_count = 0;
         $grand_total = 0;

    foreach($items_purchased_array as $item){
       if (!$mail->addEmbeddedImage(getcwd() . '/' . $item['image'],'product_pic'.$i)) {
       echo 'Failed to attach '. getcwd() . '/' . $item['image'],'product_pic'.$i;
    }

      </tbody>
580

Answer

Solution:

Here was what i did to fix this

  if (!$mail->addEmbeddedImage(getcwd().'/'.trim($item['image']),trim('product_pic'.$i))){
                    echo 'Failed to attach '.getcwd().'/'.$item['image'],('product_pic'.$i);

People are also looking for solutions to the problem: php - Symfony4 Serializer problem with unusual property name

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.