How do you send mail via PHP with attachment of HTML file? -> Content of HTML file (code) is within string in DB. Can there be some smart way reely script to get this done? I'd rather not keep file localy, I have to see clearly from DB and send it straightaway as attachment (not incorporated in body).
For those who have a difficult time obtaining the headers right, you could use something similar to PHP Mailer rather than reinventing the wheel.
I love pear.
<? include('Mail.php'); include('Mail/mime.php'); $text = 'Text version of email'; $html = '<html><body>HTML version of email</body></html>'; $file = './files/example.zip'; $crlf = "rn"; $hdrs = array( 'From' => 'firstname.lastname@example.org', 'To' => 'email@example.com', 'Subject' => 'Test mime message' ); $mime = new Mail_mime($crlf); $mime->setTXTBody($text); $mime->setHTMLBody($html); $mime->addAttachment($file,'application/octet-stream'); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mail =& Mail::factory('mail', $params); $mail->send('firstname.lastname@example.org', $hdrs, $body); ?>
You need to have the ability to follow these instructions on delivering email accessories. You'll need to change your code to see a string in the database rather than reading through the items in personal files.