943,660 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1881
  • PHP RSS
Mar 31st, 2008
0

help in mail attachment

Expand Post »
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
Quote ...

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
Similar Threads
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Mar 31st, 2008
-1

Re: help in mail attachment

my code
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 9
Solved Threads: 4
Junior Poster
queenc is offline Offline
145 posts
since Mar 2008
Mar 31st, 2008
0

Re: help in mail attachment

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
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sszettella is offline Offline
1 posts
since Mar 2008
Mar 31st, 2008
0

Re: help in mail attachment

ouch
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Real-Time Currency
Next Thread in PHP Forum Timeline: PHP Searching Problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC