Jump to content


Photo

my script to send email with attachment does not work.....


  • Please log in to reply
No replies to this topic

#1 julieta

julieta
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 08 September 2006 - 02:50 PM

Hi, I am new to this forum and brand new to php. I have a small program in flash, from which i call a php file which sends an e-mail to the adress that the user inputs in flash.  It is working fine. But now i want to make that php file send an attachment along with the email. I have copied several scripts, but I haven't been able to make any of them work. Here I have one of them. It sends the email (i think it does it twice, but that's not an issue) but for some reason, it does not send the file that I want to attach.  The file I want to attach is "exported.jpg" and it is located in the same directory as the php script. Could some one please please check the code to see what i am doing wrong? I am desperate.      Thanks in advance!! :'(


<?


$to = $theEmail;
$subject = "Dibujo de Zotz";

$fileatt = 'exported.jpg';
$fileatttype = "image/jpeg";
$fileattname = "newname.jpg";


$headers = "From: webmaster@gowansnet.com";
$body = " ". $theMessage;

$file = fopen( $fileatt, 'rb' );
        $data = fread( $file, filesize( $fileatt ) );
        fclose( $file );
       
       
$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}\"";
   
        $message = "This is a multi-part message in MIME format.\n\n" .
                "--{$mime_boundary}\n" .
                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
                "Content-Transfer-Encoding: 7bit\n\n" .
                $message . "\n\n";
   
        $data = chunk_split( base64_encode( $data ) );
               
        $message .= "--{$mime_boundary}\n" .
                "Content-Type: {$fileatttype};\n" .
                " name=\"{$fileattname}\"\n" .
                "Content-Disposition: attachment;\n" .
                " filename=\"{$fileattname}\"\n" .
                "Content-Transfer-Encoding: base64\n\n" .
                $data . "\n\n" .
                "--{$mime_boundary}--\n";


@mail($to,$subject,$message,$headers);
if(mail($to,$subject,$message,$headers)) {
$sentok=1;
} else {
$sentok=0;
}
echo "sentok=".$sentok;
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users