Jump to content

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


julieta

Recommended Posts

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;
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.