Results 1 to 3 of 3

Thread: mail with attachment problems

  1. #1

    mail with attachment problems

    Hi. I have the following code:
    Code:
    else if(file_exists("site".$timp.".zip"))
     {$file=fopen("site".$timp.".zip", "rb");
     $data=fread($file, filesize("site".$timp.".zip"));
     fclose($file);
     $data=chunk_split(base64_encode($data));
     $message.="Content-Type:{\"application/octet-stream\"};\n"."name=\"site".$timp.".zip\"\n"."Content-Disposition: attachment;\n"."filename=\"site".$timp.".zip\"\n"."Content-Transfer-Encoding: base64\n\n".$data."\n\n";
     $message.="--{{$mime_boundary}\n";
     unset($data);
     unset($file);
     if(mail($to, $subject, $message, $headers))
      {header("Location: comanda_primita.html");}
    The problem with it is, there is no attachment. Instead, at the end of the mail I get:
    --==Multipart_Boundary_x1074db4782f70d7323f462617b73 ab9dx
    Content-Type"application/octet-stream"};
    name="site1256892830.zip"
    Content-Disposition: attachment;
    filename="site1256892830.zip"
    Content-Transfer-Encoding: base64

    UEsHCFBLAwQUAAAACAC5Vl47UnvYAEYJAACNUgAAFAAAADEyNT Y4OTI4MzB1cGxvYWQucGhw7Rtr
    b9w28vMGyH/QCQayRrIbr5M0qR0l9ebWhQHbCWpfcLnaEGgt18urXpW4iV3D//2GD2lJkdL6dYe0
    x7RxreHMcGY4Lz769n0+zx8/KvDvC1Lgvh/FqCyHGJWXf5B8CGP++vbjR2uUJHkAP3Cff8JYkOJv
    3gTw/rX3CUCzrMAomvfXwt29/cmRh0pvbUZKgov1x496V2TWJ2W4yOMMTfE0nJEY9+X4r09okoc p
    SvCT03WG3LtayxGdB3zSYY0lMLYZQpJ9xauZPfM4n3VOwkQevE PT6S7HFgPX10KXwbsyjwnlQ35J
    KPaHYnJ/CKP+M+/VBv8jTJEFfpljPL0Mi8U0i2c/XaJ5lg2jLPHZ+KzIksD/ZTg4OuDf5eLs3zii
    gf8BF/CPx/mzgQSXJTrHgX+4SPCWtxZ++nh0/GsKH6cnxUn6qcCpOpCLbz52jGM8y9J6jIpvPjZJ
    EInrEcy+OPxDllI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2y7QFMr
    oxbey8RqSey1FcW6JppVsa0oVjVRkaDt9CNFX8XeyqV0l9JdSn cp3aX07zilt23x+E5DolfbktOt
    9nMAI0dqNola0ni7WbrKjOS3TJCtORytyDo2Ic2kcz8plynHfk zcKo0tOrpF8do4aMHRGhurtFke
    CnTu+tsVMgPj7qbVwqItKqI6LG4cFVEVFnaeM5K2nKnrXD1ARD HWmANIHq/PMZriogT7F1kCOOxG
    U1xl4oSEBUqnQTJ91RfXwfxONIFfw7OM+/Jl4AfBwSKmEHkFDccSGl5cLemvLzg/MRGTMD3YO5gM
    PsOshF1rjoYbsEpDn91Z4pQOjiG+t7ykYvo8IRd4us1R6llP/CtdjusTX79nPZ6T0oN/keA0YKw8
    OeqR1GMyeDOWKSgYjDEfDAyeplgU+srneYxIuu1Fc1SAkUEYUm aDN29e/TgYnfg6ERignOFiMEmj
    bErS8y3v9RmRM9ar5vPvbe2cxyqNOOdhd+AhviAlLY0b7NGGL1 0CBSN+rcCwg1mW49R+3e0XZ/za
    v7c2RRQFM0hV0z6neuaxnyX5w3pRzp2hN4virMQCX+ESzRfpby G/aO+foRL/8DLEzAKAycYFraKt
    ZuSrEx/lQBqB92bp8yyimA5KCoIlJ/618AR26w+GN8Rq2P/vpMwzQOKOhihF0TwBuODBZL4hH8s6
    CrXkSjKllsvY09fRvpC9RVpiKu2hfNeW/DZnTxS6FnsDfkfVmSLNKIpD8TICBxs86wkW+tDb0Rv5
    wEFkoxUOpczBZunwJo6p+BNrWm7hUnIiSWn4Vc3tRq6lN0wP5F 1cQljlB3ExO7Nb+pmuZrurwZ+m
    ty1Bmol1L9I/n5prh9W1q3igYA09HVl6Sp356Efhh3I3D374E3u/wtz1mVe9pIHfpILwm6xV6sMH
    WVFxwXqsyjHF19LY7EEIOCaq/HL2rQD5+5IKRmRl3EeX2YKeKtdO0JSw1ywqqHrh0oQ1yagOql6 m
    qDD5ZES8oKhkq+55PPEaRDvWbgre9dZjXS5Am7Lq841KbP6aQo VUryYMWIOyf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5waHBQSwECAAAUAAAACAC5
    Vl47pKJIyu4JAAAkJQAAGwAAAAAAAAAAACAAAACICQAAMTI1Nj g5MjgzMGNsYXNzLmVhc3l6aXAu
    cGhwUEsFBgAAAAACAAIAiwAAALsTAAAiAENvbXByZXNzZWQvU3 BsaXR0ZWQgYnkgUEhQIEVhc3la
    SVA=

    --{==Multipart_Boundary_x1074db4782f70d7323f462617b7 3ab9dx
    Does anyone know what's wrong with the code? Thank you in advance.

    PS: This script also sends multiple attachments (if there are multiple files)...But since it doesn't send even one attachment....

  2. #2
    I forgot to copy this part of the code:
    Code:
    $headers="From: $from";
    $semi_rand=md5(time());
    $mime_boundary="==Multipart_Boundary_x{$semi_rand}x";
    $header.="\nMIME-Version: 1.0\n"."Content-Type: multipart/mixed;\n"."boundary=\"{$mime_boundary}\"";
    So if you were thinking that the headers weren't set...they were...

  3. #3
    439
    posts
    Registered User
    use pear mail, really easy to add file attachments and, just generally a better way to send mail with php:

    http://pear.php.net/package/Mail

    Below I've copied and pasted a basic version of what I have done with it.

    PHP Code:
    <?php
    #PEAR MAIL INCLUDES
    require_once("Mail.php");
    require_once(
    "Mail/mime.php");
    # - EMAIL SETTINGS
    $from "My Website <noreply@mywebsite.com>";
    $to   'user@test.com';

    $msg     $_POST['my_msg'];
    $attach    $_FILES['attach'];

    //SUBJECT SETTINGS
    $sub  =    'My Subject';

    //HOST PORT SETTINGS
    $host 'localhost';
    $port 25;

            
    # - EMAIL HEADERS
    $headers = array('From' => $from'To' => $to'Subject' => $sub);
        
    # - COMPOSE EMAIL
    $mime = new Mail_mime("\n");
    $mime->setHTMLBody($msg);

    //FILE ATTACHMENT
    if(isset($attach))
    {
        
    $file        $attach['tmp_name'];
        
    $file_name    $attach['name'];
        
    $file_type    $attach['type'];
        
    $file_size    $attach['size'];
        
    $file_error    $attach['error'];            
        
        if(
    $file_error != 1)
        {                    
            if(
    $file_type != 'application/pdf' || $file_type != 'application/msword')
            {                        
                if(
    $file_size <= 1572864)
                {
                    
    $mime->addAttachment($file$file_type$file_nametrue'base64');                             
                }
    //end file size                        
            
    }//end file type                        
        
    }//end file error                    
    }//end if file set

    $body $mime->get();
    $hdrs $mime->headers($headers);                
    $smtp Mail::factory('smtp', array('host' => $host'port' => $port'auth' => false));
            
    # - SEND EMAIL
    $mail $smtp->send($to$hdrs$body);

    if (
    PEAR::isError($mail))
    {
                
        
    $error    "An error occurred sending your email. Please try again.";
                        
    }else{

        
    //REDIRECT OR SAY MESSAGE HERE!
        
    }

    ?>
    You would have to tweak it for your own use, I recommend reading the documentation. Hope this helps
    Last edited by Patch^; October 30th, 2009 at 11:53 AM.
    while ( ! ( succeed = try() ) );

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012