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

my code

<?php
function mail_attachment ($from , $to, $subject, $message, $attachment){

$attachment="home/website/public_html/simple.txt";
    $fileatt = $attachment; // Path to the file                  
    $fileatt_type = "application/octet-stream"; // File Type 
    $start=    strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
    $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the     attachment 

    $email_from = $from; // Who the email is from 
    $email_subject =  $subject; // The Subject of the email 
    $email_txt = $message; // Message that the email has in it 
    
    $email_to = $to; // Who the email is to

    $headers = "From: ".$email_from;

    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file); 
    $msg_txt="\n\nMail created using free code from 4word systems : http://4wordsystems.com";

    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
    $headers .= "\nMIME-Version: 1.0\n" . 
            "Content-Type: multipart/mixed;\n" . 
            " boundary=\"{$mime_boundary}\""; 

    $email_txt .= $msg_txt;
    
    $email_message .= "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
               "Content-Transfer-Encoding: 7bit\n\n" . 
    $email_txt . "\n\n"; 

    $data = chunk_split(base64_encode($data)); 

    $email_message .= "--{$mime_boundary}\n" . 
                  "Content-Type: {$fileatt_type};\n" . 
                  " name=\"{$fileatt_name}\"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename=\"{$fileatt_name}\"\n" . 
                  "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                  "--{$mime_boundary}--\n"; 


    $ok = @mail($email_to, $email_subject, $email_message, $headers); 

    if($ok) { 
    } else { 
        die("Sorry but the email could not be sent. Please go back and try again!"); 
    } 
}
?>
commented: Plagiarism is BAD! -1

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

$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

ouch :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.