User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,680 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,185 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 231 | Replies: 9
Reply
Join Date: Sep 2007
Posts: 19
Reputation: ditty is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
ditty ditty is offline Offline
Newbie Poster

Pls help me...very Urgent...Code for Sending attatchment with mail...

  #1  
Jul 10th, 2008
Can anybody help me to send attatchment with mail...Pls help me...Very urgent...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 522
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Pro

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #2  
Jul 10th, 2008
Hello ...
Try this code..
  1. <?php
  2. 2.
  3. $fileatt = ""; // Path to the file
  4. 3.
  5. $fileatt_type = "application/octet-stream"; // File Type
  6. 4.
  7. $fileatt_name = ""; // Filename that will be used for the file as the attachment
  8. 5.
  9.  
  10. 6.
  11. $email_from = ""; // Who the email is from
  12. 7.
  13. $email_subject = ""; // The Subject of the email
  14. 8.
  15. $email_txt = ""; // Message that the email has in it
  16. 9.
  17.  
  18. 10.
  19. $email_to = ""; // Who the email is too
  20. 11.
  21.  
  22. 12.
  23. $headers = "From: ".$email_from;
  24. 13.
  25.  
  26. 14.
  27. $file = fopen($fileatt,'rb');
  28. 15.
  29. $data = fread($file,filesize($fileatt));
  30. 16.
  31. fclose($file);
  32. 17.
  33.  
  34. 18.
  35. $semi_rand = md5(time());
  36. 19.
  37. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  38. 20.
  39.  
  40. 21.
  41. $headers .= "\nMIME-Version: 1.0\n" .
  42. 22.
  43. "Content-Type: multipart/mixed;\n" .
  44. 23.
  45. " boundary=\"{$mime_boundary}\"";
  46. 24.
  47.  
  48. 25.
  49. $email_message .= "This is a multi-part message in MIME format.\n\n" .
  50. 26.
  51. "--{$mime_boundary}\n" .
  52. 27.
  53. "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  54. 28.
  55. "Content-Transfer-Encoding: 7bit\n\n" .
  56. 29.
  57. $email_message . "\n\n";
  58. 30.
  59.  
  60. 31.
  61. $data = chunk_split(base64_encode($data));
  62. 32.
  63.  
  64. 33.
  65. $email_message .= "--{$mime_boundary}\n" .
  66. 34.
  67. "Content-Type: {$fileatt_type};\n" .
  68. 35.
  69. " name=\"{$fileatt_name}\"\n" .
  70. 36.
  71. //"Content-Disposition: attachment;\n" .
  72. 37.
  73. //" filename=\"{$fileatt_name}\"\n" .
  74. 38.
  75. "Content-Transfer-Encoding: base64\n\n" .
  76. 39.
  77. $data . "\n\n" .
  78. 40.
  79. "--{$mime_boundary}--\n";
  80. 41.
  81.  
  82. 42.
  83. $ok = @mail($email_to, $email_subject, $email_message, $headers);
  84. 43.
  85.  
  86. 44.
  87. if($ok) {
  88. 45.
  89. echo "<font face=verdana size=2>The file was successfully sent!</font>";
  90. 46.
  91. } else {
  92. 47.
  93. die("Sorry but the email could not be sent. Please go back and try again!");
  94. 48.
  95. }
  96. 49.
  97. ?>
  98. Thanks...
  99.  
Reply With Quote  
Join Date: Sep 2007
Posts: 19
Reputation: ditty is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
ditty ditty is offline Offline
Newbie Poster

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #3  
Jul 10th, 2008
Thank you shanthi....thank you so much...
Reply With Quote  
Join Date: Sep 2007
Posts: 19
Reputation: ditty is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
ditty ditty is offline Offline
Newbie Poster

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #4  
Jul 10th, 2008
Shanthi...Can you give me an example?
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 522
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Pro

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #5  
Jul 10th, 2008
You just fill up that variables and execute that code...
put echo before $email_message.
Then you will get what is going to our mail...
Try and ask if any errors arise...
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 834
Reputation: ithelp is on a distinguished road 
Rep Power: 4
Solved Threads: 61
ithelp ithelp is offline Offline
Practically a Posting Shark

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #6  
Jul 11th, 2008
I do not think you will not find many people here who will spoon feed you everything to complete your homework, put some effort first.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #7  
Jul 11th, 2008
Originally Posted by ithelp View Post
I do not think you will not find many people here who will spoon feed you everything to complete your homework, put some effort first.


echo
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Aug 2007
Posts: 147
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #8  
Jul 11th, 2008
Hi.
Thanks for the code,
Just it is working, and the mail sends with the attachment, but i have the following errors while sending:

Warning: fread(): supplied argument is not a valid stream resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\email\email.php on line 11

Warning: fclose(): supplied argument is not a valid stream resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\email\email.php on line 12
The file was successfully sent!

and secondly, I dont have the email_txt in my mail_box, and also the attachment files not open.

what can be the problem

Originally Posted by Shanti Chepuru View Post
You just fill up that variables and execute that code...
put echo before $email_message.
Then you will get what is going to our mail...
Try and ask if any errors arise...
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 534
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 50
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Posting Pro

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #9  
Jul 11th, 2008
May I present my greatest work utility, let me know if you need help using it:
http://us2.php.net/manual/en/function.fread.php
http://us2.php.net/manual/en/function.fclose.php
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
Reply With Quote  
Join Date: Aug 2007
Posts: 147
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: Pls help me...very Urgent...Code for Sending attatchment with mail...

  #10  
Jul 12th, 2008
HI.
if you have something useful, then you can post it.

Thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:18 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC