generate php image without saving to disk and send attachment

1

So I have a script that generates a ticket in the image format (using imagegif ()).

I would like to know if you have how I can send this attachment (use phpmailer) without having to save the image to disk. Reason? Avoid getting discs.

I mean, is there any magic for me to do that?

    
asked by anonymous 20.01.2015 / 17:45

1 answer

3

It is possible using the AddStringAttachment function.

In your case it would look something like this:

$mail = new PHPMailer();
// ....
ob_clean(); // limpa qualquer coisa no buffer de saída
ob_start();
imagegif($img); // gera a imagem (assumindo que já exista uma imagem em $img)
$gif = ob_get_clean(); // $gif agora contém a imagem gerada

$mail->AddStringAttachment($gif, 'boleto.gif'); // 'boleto.gif' é o nome do anexo que vai aparecer no e-mail
    
20.01.2015 / 18:53