+ Reply to Thread
Results 1 to 9 of 9

Thread: php submit form to .txt file

  1. #1
    Newbie ferreirawebs is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    4

    Post php submit form to .txt file

    stuck on this one

    my boss had recently asked me to try and figure out if it is possible to have a form on our website that users may fill out and have that information emailed to us within a .txt file as oppose to just an email.

    example;

    user files out a form with the following fields:
    name:
    email:
    message:
    etc..

    that form then gets emailed to us, and within that email is a .txt attachment.

    once we open that attachment we see the following:

    name: john smith
    email: email
    message: hey
    etc..

    does anyone know if this is possible?? if so, please tell me how!!

    regards.

  2. #2
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,618
    Blog Entries
    7

    Re: php submit form to .txt file

    of course it is possible.

    just use fopen to open the file, if you open it with "append" you just add more info to the file, then use fwrite to write to the fie, and fclose to close the file..

    read more: PHP: fopen - Manual
    __________________________________________
    Ask me: Orjan | Contribute to the Wiki! | Make your own Programming blog!
    I usually play eRepublik and Travian when I'm not on CodeCall

  3. #3
    Newbie ferreirawebs is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    4

    Re: php submit form to .txt file

    from what i understand this just creates a notepad file on the sites server?

    although this way works it's not ideal for what we're trying to do.

    we would like an actual notepad file emailed to us so that we may upload that information to filemaker.

    the way you just explained would mean we would have to log into the server everytime in which case we might as well just copy the information from the email using a regular email form.

    is there any other way of doing this?

  4. #4
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,618
    Blog Entries
    7

    Re: php submit form to .txt file

    just format the email how you'd like so it suits filemake import... copy and paste from email to your mail program, or send the information as an attachment to the email. then, just look for how to send a multipart email from php...
    __________________________________________
    Ask me: Orjan | Contribute to the Wiki! | Make your own Programming blog!
    I usually play eRepublik and Travian when I'm not on CodeCall

  5. #5
    Newbie ferreirawebs is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    4

    Re: php submit form to .txt file

    Quote Originally Posted by Orjan View Post
    just format the email how you'd like so it suits filemake import... copy and paste from email to your mail program, or send the information as an attachment to the email. then, just look for how to send a multipart email from php...
    which brings me to my question. how exactly do i send the information as an attachment, or will i get my answer by doing a multipart email from php search?

  6. #6
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    20
    Posts
    2,223
    Blog Entries
    8

    Re: php submit form to .txt file

    Sending a file as an attachment is a bit complicated. You need to encode the file and place it in the mail() headers.

    I found an example online.
    Code:
    <?PHP
    $headers 
    "From: Me <me@email.com>";//put you own stuff here or use a variable
    $to 'blayne4k@gmail.com';// same as above
    $subject 'Testing Inline attachment HTML Emails';//your own stuff goes here
    $html ="<img src='beerchug.gif'><br /><br />
    <b>This</b> is HTML <span style='background:cyan'>and this is a cyan highlight</span>
    <br />So this should be a new line.<br /><br />This should be a new line with a space between the above.
    <br />Here's dead Al<br><img src='DeadAl.jpg'><br />He is dead in this photo!<br />This is a martyr, well
    OK then I think I will pass on looking like that all blowed up and all.<br /><br />So much for being a martyr!<br /> He's just another dead terrorist in the pile of the others ... ougggh nooooo!"
    ;//make up your own html or use an include
    //the below is your own plain text message (all the $message(x))
    $messagez 'Plain text is boring...';// or make up your own for plain text message

    //Now lets set up some attachments (two in this case)
        //first file to attach
        
    $fileatt2 '../images/beerchug.gif';//put the relative path to the file here on your server
        
    $fileatt_name2 'beerchug.gif';//just the name of the file here
        
    $fileatt_type2 filetype($fileatt2);
        
    $file2 fopen($fileatt2,'rb');
        
    $data2 fread($file2,filesize($fileatt2));
        
    fclose($file2);

        
    //another file to attach
        
    $fileatt 'DeadAl.jpg';//relative path to image two and more (this one is in the same directory)
        
    $fileatt_name 'DeadAl.jpg';//just the name of the file
        
    $fileatt_type filetype($fileatt);
        
    $file fopen($fileatt,'rb');
        
    $data fread($file,filesize($fileatt));
        
    fclose($file);

    // Generate a boundary string that is unique
    $semi_rand md5(time());
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
        
    "Content-Type: multipart/alternative;\n" .
        
    " boundary=\"{$mime_boundary}\"";
    $message "--{$mime_boundary}\n" .
        
    "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
        
    "Content-Transfer-Encoding: 7bit\n\n" .
        
    "<font face=Arial>" .
        
    $html."\r\n";
        
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
        
    "Content-Transfer-Encoding: 7bit\n\n" .
        
    $messagez;

    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
        
    "Content-Type: multipart/mixed;\n" .
        
    " boundary=\"{$mime_boundary}\"";

    // Base64 encode the file data
    $data2 chunk_split(base64_encode($data2));

    // Add file attachment to the message
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: image/gif;\n" // {$fileatt_type}
        
    " name=\"{$fileatt_name2}\"\n" .
        
    "Content-Disposition: inline;\n" .
        
    " filename=\"{$fileatt_name2}\"\n" .
        
    "Content-Transfer-Encoding: base64\n\n" .
        
    $data2 "\n\n" .
        
    "--{$mime_boundary}--\n";

    // Add another file attachment to the message as many as you have
    $data chunk_split(base64_encode($data));

    // Add file attachment to the message
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: image/jpg;\n" // {$fileatt_type}
        
    " name=\"{$fileatt_name}\"\n" .
        
    "Content-Disposition: inline;\n" .
        
    " filename=\"{$fileatt_name}\"\n" .
        
    "Content-Transfer-Encoding: base64\n\n" .
        
    $data "\n\n" .
        
    "--{$mime_boundary}--\n";

    // Send the message
    $send mail($to$subject$message$headers);
    if (
    $send) {
        echo 
    "<p>Email Sent to intended recipients successfully!</p>";
    } else {
        echo 
    "<p>Mail could not be sent. You missed something in the script. Sorry!</p>";
    }
    ?>

  7. #7
    Newbie dmaxcreative is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    3

    Re: php submit form to .txt file

    hi! I am a newbie... I have a small doubt.....Why PHP Submit form to .txt file...?

  8. #8
    Newbie ferreirawebs is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    4

    Re: php submit form to .txt file

    i've tried this coding, but it doesn't seem to add the attached file?
    instead i just get the form emailed to me like i normally do with some of the coding displayed at the end. (i.e. Content-Disposition: inline;
    filename=""
    Content-Transfer-Encoding: base64)

    Do you know what I could be doing wrong, or is there an easier way?

    Quote Originally Posted by BlaineSch View Post
    Sending a file as an attachment is a bit complicated. You need to encode the file and place it in the mail() headers.

    I found an example online.
    Code:
    <?PHP
    $headers 
    "From: Me <me@email.com>";//put you own stuff here or use a variable
    $to 'blayne4k@gmail.com';// same as above
    $subject 'Testing Inline attachment HTML Emails';//your own stuff goes here
    $html ="<img src='beerchug.gif'><br /><br />
    <b>This</b> is HTML <span style='background:cyan'>and this is a cyan highlight</span>
    <br />So this should be a new line.<br /><br />This should be a new line with a space between the above.
    <br />Here's dead Al<br><img src='DeadAl.jpg'><br />He is dead in this photo!<br />This is a martyr, well
    OK then I think I will pass on looking like that all blowed up and all.<br /><br />So much for being a martyr!<br /> He's just another dead terrorist in the pile of the others ... ougggh nooooo!"
    ;//make up your own html or use an include
    //the below is your own plain text message (all the $message(x))
    $messagez 'Plain text is boring...';// or make up your own for plain text message

    //Now lets set up some attachments (two in this case)
        //first file to attach
        
    $fileatt2 '../images/beerchug.gif';//put the relative path to the file here on your server
        
    $fileatt_name2 'beerchug.gif';//just the name of the file here
        
    $fileatt_type2 filetype($fileatt2);
        
    $file2 fopen($fileatt2,'rb');
        
    $data2 fread($file2,filesize($fileatt2));
        
    fclose($file2);

        
    //another file to attach
        
    $fileatt 'DeadAl.jpg';//relative path to image two and more (this one is in the same directory)
        
    $fileatt_name 'DeadAl.jpg';//just the name of the file
        
    $fileatt_type filetype($fileatt);
        
    $file fopen($fileatt,'rb');
        
    $data fread($file,filesize($fileatt));
        
    fclose($file);

    // Generate a boundary string that is unique
    $semi_rand md5(time());
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
        
    "Content-Type: multipart/alternative;\n" .
        
    " boundary=\"{$mime_boundary}\"";
    $message "--{$mime_boundary}\n" .
        
    "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
        
    "Content-Transfer-Encoding: 7bit\n\n" .
        
    "<font face=Arial>" .
        
    $html."\r\n";
        
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
        
    "Content-Transfer-Encoding: 7bit\n\n" .
        
    $messagez;

    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
        
    "Content-Type: multipart/mixed;\n" .
        
    " boundary=\"{$mime_boundary}\"";

    // Base64 encode the file data
    $data2 chunk_split(base64_encode($data2));

    // Add file attachment to the message
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: image/gif;\n" // {$fileatt_type}
        
    " name=\"{$fileatt_name2}\"\n" .
        
    "Content-Disposition: inline;\n" .
        
    " filename=\"{$fileatt_name2}\"\n" .
        
    "Content-Transfer-Encoding: base64\n\n" .
        
    $data2 "\n\n" .
        
    "--{$mime_boundary}--\n";

    // Add another file attachment to the message as many as you have
    $data chunk_split(base64_encode($data));

    // Add file attachment to the message
    $message .= "--{$mime_boundary}\n" .
        
    "Content-Type: image/jpg;\n" // {$fileatt_type}
        
    " name=\"{$fileatt_name}\"\n" .
        
    "Content-Disposition: inline;\n" .
        
    " filename=\"{$fileatt_name}\"\n" .
        
    "Content-Transfer-Encoding: base64\n\n" .
        
    $data "\n\n" .
        
    "--{$mime_boundary}--\n";

    // Send the message
    $send mail($to$subject$message$headers);
    if (
    $send) {
        echo 
    "<p>Email Sent to intended recipients successfully!</p>";
    } else {
        echo 
    "<p>Mail could not be sent. You missed something in the script. Sorry!</p>";
    }
    ?>

  9. #9
    Newbie dmaxcreative is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    3

    Re: php submit form to .txt file

    hi, thanks a lot to ur Reply.....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 43
    Last Post: 01-16-2010, 10:35 AM
  2. Replies: 0
    Last Post: 12-27-2009, 04:59 PM
  3. Detect Character Set
    By dargueta in forum General Programming
    Replies: 14
    Last Post: 09-10-2009, 04:55 PM
  4. Linux/Bash: Check if a file exists
    By Tor in forum Shell Scripts
    Replies: 4
    Last Post: 07-10-2009, 01:28 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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