Forum Moderators: coopster

Message Too Old, No Replies

Sending HTML file attachment with PHP mail()

HTML attachment arrives as text attachment

         

Paul in South Africa

12:28 pm on Mar 11, 2003 (gmt 0)

10+ Year Member



I am trying to send an email using PHP mail(). Part of the mail is a message that is entered in a text box and the other part should be sent as an HTML attachment (the content of this is generated from a database). The email is sent with the correct text in the message body but the attachment comes through as a file with a .txt extension.

A partial code example follows:

$headers .= "Content-Type: multipart/mixed; boundary=lkufg46bsfd\n";
$message = "--lkufg46bsfd

$comments
--lkufg46bsfd
Content-type: text/html; name=$candidate_row[last].htm\n
Content-disposition: attachment; filename=$candidate_row[last].htm\n

<html>Generated content</html>
--lkufg46bsfd--
";
mail($to, $subject, $message, $headers);

The first few lines of the attachment that arrives are

Content-type: text/html; name="Coetzer.htm"

Content-disposition: attachment; filename="Coetzer.htm"

<html>and the rest of the HTML as it should be.

If I take the first few lines of the attachment out (up to the beginning of the <html> and save it with the extension .htm it then displays exactly as it should in a browser.

Can anybody spot my mistake? It is driving me mad.

<edit>spelling</edit>

hakre

8:59 am on Mar 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi paul!

i have no answer on your question in specific, but for multipart messages (even with the mail function) i would take a look at phpmailer. it's a php class which is an easy interface to send mime mails (html mails, inline images, attachments) with the php mail function and directly through servers. just google for it, will be the first entry.

DrDoc

8:20 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any quotes in the HTML? Since you do
$message="...";
they could mess it up.

Try this instead:

$message=<<<END
...
END;