Question

How do I send mail via PHP with attachment of HTML file? -> Content of HTML file (code) is in string in DB. Is there some easy way or free script to do this? I don't want to store the file localy, I need to read it out of DB and send it straightaway as attachment (not included in body).

Was it helpful?

Solution

If you have a hard time getting the headers right, you can always use something like PHP Mailer instead of reinventing the wheel.

OTHER TIPS

I like 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'    => 'someone@domain.pl',
              'To'      => 'someone@domain.pl',
              '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('mail@domain.pl', $hdrs, $body); 
?>

You should be able to follow these instructions on sending email attachments. You will simply need to adjust your code to read a string from the database instead of reading the contents of a file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top