help in mail attachment

Thread Solved

Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

help in mail attachment

 
0
  #1
Mar 31st, 2008
hi
In my mail attachment i am able to recieve the attachment but the file size is 0kb.
it is showing the below warnings
please do tell the error in my code

home/wesite/public_html/profiles/resumes/153/
Warning: fopen(home/website/public_html/simple.txt) [function.fopen]: failed to open stream: No such file or directory in /home/website/public_html/mail_attachment.php on line 18

Warning: filesize() [function.filesize]: stat failed for home/website/public_html/simple.txt in /home/website/public_html/mail_attachment.php on line 19

Warning: fread(): supplied argument is not a valid stream resource in /home/wesite/public_html/mail_attachment.php on line 19

Warning: fclose(): supplied argument is not a valid stream resource in /home/website/public_html/mail_attachment.php on line 20
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 145
Reputation: queenc is an unknown quantity at this point 
Solved Threads: 4
queenc's Avatar
queenc queenc is offline Offline
Junior Poster

Re: help in mail attachment

 
-1
  #2
Mar 31st, 2008
my code
  1. <?php
  2. function mail_attachment ($from , $to, $subject, $message, $attachment){
  3.  
  4. $attachment="home/website/public_html/simple.txt";
  5. $fileatt = $attachment; // Path to the file
  6. $fileatt_type = "application/octet-stream"; // File Type
  7. $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
  8. $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment
  9.  
  10. $email_from = $from; // Who the email is from
  11. $email_subject = $subject; // The Subject of the email
  12. $email_txt = $message; // Message that the email has in it
  13.  
  14. $email_to = $to; // Who the email is to
  15.  
  16. $headers = "From: ".$email_from;
  17.  
  18. $file = fopen($fileatt,'rb');
  19. $data = fread($file,filesize($fileatt));
  20. fclose($file);
  21. $msg_txt="\n\nMail created using free code from 4word systems : http://4wordsystems.com";
  22.  
  23. $semi_rand = md5(time());
  24. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  25.  
  26. $headers .= "\nMIME-Version: 1.0\n" .
  27. "Content-Type: multipart/mixed;\n" .
  28. " boundary=\"{$mime_boundary}\"";
  29.  
  30. $email_txt .= $msg_txt;
  31.  
  32. $email_message .= "This is a multi-part message in MIME format.\n\n" .
  33. "--{$mime_boundary}\n" .
  34. "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  35. "Content-Transfer-Encoding: 7bit\n\n" .
  36. $email_txt . "\n\n";
  37.  
  38. $data = chunk_split(base64_encode($data));
  39.  
  40. $email_message .= "--{$mime_boundary}\n" .
  41. "Content-Type: {$fileatt_type};\n" .
  42. " name=\"{$fileatt_name}\"\n" .
  43. //"Content-Disposition: attachment;\n" .
  44. //" filename=\"{$fileatt_name}\"\n" .
  45. "Content-Transfer-Encoding: base64\n\n" .
  46. $data . "\n\n" .
  47. "--{$mime_boundary}--\n";
  48.  
  49.  
  50. $ok = @mail($email_to, $email_subject, $email_message, $headers);
  51.  
  52. if($ok) {
  53. } else {
  54. die("Sorry but the email could not be sent. Please go back and try again!");
  55. }
  56. }
  57. ?>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: sszettella is an unknown quantity at this point 
Solved Threads: 1
sszettella sszettella is offline Offline
Newbie Poster

Re: help in mail attachment

 
0
  #3
Mar 31st, 2008
queenc:

Interesting that you claim your posted code to be "my" code. As I see it, you copied code from 4word systems (available here: http://www.4wordsystems.com/php_mail_attachment.php).

It's pretty obvious from this line in the code you posted
  1. $msg_txt="\n\nMail created using free code from 4word systems : http://4wordsystems.com";
At the very least, please give credit where credit is due

Steve Szettella
4word systems, inc.
http://www.4wordsystems.com
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 160
Reputation: w_3rabi is an unknown quantity at this point 
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: help in mail attachment

 
0
  #4
Mar 31st, 2008
ouch
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC