Does anyone know of a way to create a dynamic jpg image in php and attach it to an email using php without having to save the file to the server?

I know how to create the image and display it in the browser using php but is it possible to redirect the image stream so I can embed it as an attachment in an email instead of output to browser?

    ob_start();
    //output the jpeg as though for display
    $jpeg = ob_get_clean();
    

      Here is how I am attaching a file to an email -

                  for($i=0;$i<$max;$i++)
                  {
                      $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
                      $this->header .= "--".$this->boundary."\n";
                      $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n";
                      $this->header .= "Content-Transfer-Encoding: base64\n";
                      $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n";
                      $this->header .= chunk_split(base64_encode($file))."\n";
                      $file = "";
                  }
      

      Weedpacket, to incorporate you suggestion, how do I give the buffer a filename so it sits in the email as a .jpg file to be viewed?

      The reason I don't want to create the imagefile on the server then attach it to the email is that the image file is previewed by the user on the website then emailed to them as confirmation and for their records. I have no use in retaining the file and certainly don't want it to clutter up my web server with an image file for every transaction.

      Any ideas?

        Write a Reply...