How to send email with attachment using PHP?

I’d suggest to use a library for sending eMails as it will handle all the header related stuff. Have a look at Zend_Mail. Sending attachments is as easy as

$mail = new Zend_Mail();

$at = $mail->createAttachment($myImage);
$at->type="image/gif";
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding    = Zend_Mime::ENCODING_8BIT;
$at->filename="test.gif";

$mail->send();

Leave a Comment