-1

i had a look on how to do this but it looks too complicated. all i want is to mail a small .txt as an attachment can anyone help please? i have this code:

$to      = "a mail adress";
$file    = "/home/rainbowcode/StatsFile.txt";
$subject = "StatsFile.txt";
$email = "a mail adress";
$message = "Here is your Statsfile; for today";
$headers = "From: $email";
mail($to, $subject, $message, $headers);
hakre
  • 193,403
  • 52
  • 435
  • 836
charlie_cat
  • 1,830
  • 7
  • 44
  • 73
  • Have you considered using a framework? Like Zend Framework: http://framework.zend.com/manual/en/zend.mail.attachments.html – Fabio Mora May 10 '11 at 07:56
  • 5
    See the "related" column for many, many duplicates. – Pekka May 10 '11 at 07:57
  • 3
    possible duplicate of [php send e-mail with attachment](http://stackoverflow.com/questions/3092821/php-send-e-mail-with-attachment) as said there, unless it's for learning, I recommend using a pre-fab package like SwiftMailer. – Pekka May 10 '11 at 07:57

2 Answers2

0

I would recommend using the PEAR Mail_Mime package to easily add attachments.

Once you've created the Mail_Mime object you'll just need to use it's addAttachment() method.

James C
  • 14,047
  • 1
  • 34
  • 43
  • i found this code, it sent mail correct but attachment StatsFile.txt is empty??? i changed the filename,upload path and email adresses for my purpose http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script please help? thank you – charlie_cat May 10 '11 at 08:23
  • i accepted some answers we use symfony framework been through related issues list but dont know enough to help myself have not a clue..i am in a learning process – charlie_cat May 10 '11 at 08:42
0

Take a look at this post . As you said it's a bit complicated but hopefully it will work.

Beatles1692
  • 5,214
  • 34
  • 65