Results 1 to 8 of 8

Thread: attaching file to email form

  1. #1
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default attaching file to email form

    Does anyone know how i would attach a file thats on a page to an email form? I figured out the whole phone email thing. but cannot figure out how to add the attachment from the page.

    i have page ringtone/getlow.php

    how can i have it so the file getlow.mp3 attaches to the email form when the user submits it?

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks alot blizzard this is just what i wanted. its great!!!

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Welcome. Glad I could help.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey i have a another question in regards to this script.

    how would i have it so that someone can just put in there mobile number and then have a radio button that displays the carrier that they click and it auto populates the @carrier.com hidden? would it be best to use mysql or a var in php? wat would the code look like?

  6. #6
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    would this script work?
    Code:
    <?php
    function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false)
    {
      $eol="\r\n";
      $mime_boundary=md5(time());
      
      # Common Headers
      $headers .= 'From: MyName<'.$fromaddress.'>'.$eol;
      $headers .= 'Reply-To: MyName<'.$fromaddress.'>'.$eol;
      $headers .= 'Return-Path: MyName<'.$fromaddress.'>'.$eol;    // these two to set reply address
      $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
      $headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
    
      # Boundry for marking the split & Multitype Headers
      $headers .= 'MIME-Version: 1.0'.$eol;
      $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
    
      $msg = "";      
      
      if ($attachments !== false)
      {
    
        for($i=0; $i < count($attachments); $i++)
        {
          if (is_file($attachments[$i]["file"]))
          {   
            # File for Attachment
            $file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
            
            $handle=fopen($attachments[$i]["file"], 'rb');
            $f_contents=fread($handle, filesize($attachments[$i]["file"]));
            $f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
            fclose($handle);
            
            # Attachment
            $msg .= "--".$mime_boundary.$eol;
            $msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
            $msg .= "Content-Transfer-Encoding: base64".$eol;
            $msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
            $msg .= $f_contents.$eol.$eol;
            
          }
        }
      }
      
      # Setup for text OR html
      $msg .= "Content-Type: multipart/alternative".$eol;
      
      # Text Version
      $msg .= "--".$mime_boundary.$eol;
      $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol;
      $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
      
      # HTML Version
      $msg .= "--".$mime_boundary.$eol;
      $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
      $msg .= "Content-Transfer-Encoding: 8bit".$eol;
      $msg .= $body.$eol.$eol;
      
      # Finished
      $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.
        
      # SEND THE EMAIL
      ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
      mail($emailaddress, $emailsubject, $msg, $headers);
      ini_restore(sendmail_from);
      echo "mail send";
    }
    
      
    # To Email Address
    $emailaddress="to@address.com";
    
    # From Email Address
    $fromaddress = "from@address.com";
    
    # Message Subject
    $emailsubject="This is a test mail with some attachments";
    
    # Use relative paths to the attachments
    $attachments = Array(
      Array("file"=>"../../test.doc", "content_type"=>"application/msword"), 
      Array("file"=>"../../123.pdf", "content_type"=>"application/pdf")
    );
    
    # Message Body
    $body="This is a message with <b>".count($attachments)."</b> attachments and maybe some <i>HTML</i>!";
    
    send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments);
    ?>

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Are you asking me or telling me?

    LOL, I don't know if it does or not. Have you tried it? If you try it and it works, then ... yes! If you try it and it doesn't, post the error you get
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok lets scratch that.

    im still learning php. i work 70 hours a week and do this on the side so not alot of free time to learn it like i should

    basically i have no idea how to do what i want.

    a form with a single field for email address.
    a hidden field with a predefined file attached to it that sends to email user inputs. I think its a simple issue but i cannot find it nor figure it out'

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
  •