SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I found an easy class to send emails w/attachment after someone has filled in a form. The only problem - I think - is that I haven't figured out how to send it either in the Excel format (.sxl) or self-extracting zip (.exe) format.

    I found a site - of course I can't remember the URL right now - but it gave a list of file formats you can send with the MIME coding, etc.

    In the end, I am now using the ZIP file format, with the following line in the class:

    $mail->add_attachment("$attachment", "evaluator.zip", "application/zip");

    I tried just changing the .zip to .exe but that doesn't work. Is it possible to send .exe files as an attachment???

    Willow

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, bad form replying to myself but I'm one step further now. The way I've done it now (see code below) is by using as media type: multipart/mixed for the self-extracting Zip file with .exe extension.

    This way the file is sent and it opens up correctly, too! BUT... the body of the email message contains miles and miles of code garbage of the file. Does anyone know how I can get rid of the file in the body?

    To be more clear I'm copying the class I'm using:

    PHP Code:
          // Send Evaluator

    /*
     *  Class mime_mail
     *  Original implementation by Sascha Schumann <sascha@schumann.cx>
     *  Modified by Tobias Ratschiller <tobias@dnet.it>:
     *      - General code clean-up
     *      - separate body- and from-property
     *      - killed some mostly un-necessary stuff
     */ 
     
    class mime_mail 
     
    {
     var 
    $parts;
     var 
    $to;
     var 
    $from;
     var 
    $headers;
     var 
    $subject;
     var 
    $body;

      
    /*
      *     void mime_mail()
      *     class constructor
      */         
     
    function mime_mail()
      {
      
    $this->parts = array();
      
    $this->to =  "";
      
    $this->from =  "";
      
    $this->subject =  "";
      
    $this->body =  "";
      
    $this->headers =  "";
      }

      
    /*
      *     void add_attachment(string message, [string name], [string ctype])
      *     Add an attachment to the mail object
      */ 
     
    function add_attachment($message$name =  ""$ctype =  "application/octet-stream")
      {
      
    $this->parts[] = array (
                               
    "ctype" => $ctype,
                               
    "message" => $message,
                               
    "encode" => $encode,
                               
    "name" => $name
                              
    );
      }

    /*
     *      void build_message(array part=
     *      Build message parts of an multipart mail
     */ 
    function build_message($part)
     {
     
    $message $part"message"];
     
    $message chunk_split(base64_encode($message));
     
    $encoding =  "base64";
     return  
    "Content-Type: ".$part"ctype"].
                            (
    $part"name"]? "; name = \"".$part"name"]. "\"" :  "").
                             
    "\nContent-Transfer-Encoding: $encoding\n\n$message\n";
     }

    /*
     *      void build_multipart()
     *      Build a multipart mail
     */ 
    function build_multipart() 
     {
     
    $boundary =  "b".md5(uniqid(time()));
     
    $multipart =  "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary";

     for(
    $i sizeof($this->parts)-1$i >= 0$i--) 
        {
        
    $multipart .=  "\n".$this->build_message($this->parts[$i]). "--$boundary";
        }
     return 
    $multipart.=  "--\n";
     }

    /*
     *      void send()
     *      Send the mail (last class-function to be called)
     */ 
    function send() 
     {
     
    $mime =  "";
     if (!empty(
    $this->from))
        
    $mime .=  "From: ".$this->from"\n";
     if (!empty(
    $this->headers))
        
    $mime .= $this->headers"\n";
        
     if (!empty(
    $this->body))
        
    $this->add_attachment($this->body,  "",  "text/plain");   
     
    $mime .=  "MIME-Version: 1.0\n".$this->build_multipart();
     
    mail($this->to$this->subject,  ""$mime);
     }
    };  
    // end of class 


     
     
    $attachment fread(fopen("evaluator.exe""r"), filesize("evaluator.exe"));

     
    $mail = new mime_mail();
     
    $mail->from "crm4sme <info@crm4sme.com>";
     
    $mail->headers "Errors-To: [email]info@crm4sme.com[/email]";
     
    $mail->to "$email";
     
    $mail->subject "Software Evaluator";
     
    $mail->body "Bal bla bla.";
     
    $mail->add_attachment("$attachment""evaluator.exe"" multipart/mixed");
     
    $mail->send(); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is really beginning to me an interesting thread, with only myself as a participant. BUT... I found the solution and figured I should post it so the next person - who like me - is searching info about this, will know what to do.

    Media type for Excel: application/vnd.ms-excel
    Media type for Self-Extracting Zip: application/x-msdownload

    And it was so simple to find out. For any file format you want to know the media type of, just send yourself a message with the attachment then - at least in outlook express - look at the properties, details and the original message. Voilą - it's right there.

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just want to say thanks for posting the answers, has helped me out!

  5. #5
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Willow
    This is really beginning to me an interesting thread, with only myself as a participant. BUT... I found the solution and figured I should post it so the next person - who like me - is searching info about this, will know what to do.

    Media type for Excel: application/vnd.ms-excel
    Media type for Self-Extracting Zip: application/x-msdownload

    And it was so simple to find out. For any file format you want to know the media type of, just send yourself a message with the attachment then - at least in outlook express - look at the properties, details and the original message. Voilą - it's right there.
    A reference for all MIME types can be found here:

    http://www.utoronto.ca/webdocs/HTMLd.../mimetype.html
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great link! I wish I'd found that earlier. I came across another link with media types but it was extremely confusing.

    This one is perfect. Thanks for posting it.

    Willow

  7. #7
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    I came across your postings because I too am researching my options in regard to sending plain text e-mails with file attachments.

    Here's my mission:

    I want to send a plain text e-mail with a single file attachment to multiple recipients using an online form.

    The script you supplied (sourced from here I think: http://phpwizard.net/resources/phpMi...etty/mail.php3) looks good, but the following questions are still nagging at me:

    1. I'm sending the message+attachment to a list of subscribers. Is it it better to
    A - bundle up all their e-mail addresses into the BCC: field of the e-mail, and call the function/class once, OR
    B - call the function multiple times - once for each subscriber with his/her address in the TO: field?

    2. I'm also comparing and contrasting the phpwizard script with the HTML Email Class available from Heyes Computing: http://www.heyes-computing.net/downl...p?script_id=4. This second example looks much more 'full-on' than the phpwizard script. It seems that if offers two approaches to sending an e-mail - using the regular php mail() function, or using an included smtp class. The comments in the example scripts repeatedly say that the smtp method is 'preferred', but don't explain why. For the sake of my own (annoying) curiousity, I'd like to know why it is preferred.

    Any comments ?

    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll be curious to see any replies/comments because I still consider myself a newbie!

  9. #9
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just reporting back some findings...

    I got some v. informative replies back from Richard Heyes to my queries. Here are the Q&A's:

    ----------------------

    Q1. There are lots of references in the example scripts to effect that the smtp method is the preferred method of sending. I'm just really curious to know why it is preferred (to the regular php mail() function I guess)? The answer is probably quite simple...

    A1. It's more versatile, in that it can send Bcc: email, adn also it seems to be more compatible. Many people had issues with the send() function which were
    resolved when switching to smtp_send().

    Q2. If I want to send a plain text message+attachment to multiple recipients from an opt-in mailing list, is it 'better' to
    a. bundle up all their e-mail addresses, throw them in the bcc: field, and send once, or
    b. send the message+attachment multiple times, 1 for each of the subscribers with their e-mail address in the To: field?

    A2: If the email is the same for all recipients, then the best would probably be to go the Bcc: option. The limit for simultaneous recipients is 100 iirc, so
    do it 100 at a time.

    ----------------------
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Florence, Italy
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for sharing this!


Bookmarks

Posting Permissions

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