Closed Thread
Results 1 to 9 of 9

Thread: php submit form to .txt file

  1. #1
    ferreirawebs is offline Newbie
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    41

    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
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  4. #3
    ferreirawebs is offline Newbie
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    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?

  5. #4
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    41

    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...
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  6. #5
    ferreirawebs is offline Newbie
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    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?

  7. #6
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    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>";
    }
    ?>

  8. #7
    dmaxcreative is offline Newbie
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Re: php submit form to .txt file

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

  9. #8
    ferreirawebs is offline Newbie
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    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>";
    }
    ?>

  10. #9
    dmaxcreative is offline Newbie
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Re: php submit form to .txt file

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

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How can I save form input on submit?
    By system32 in forum PHP Development
    Replies: 4
    Last Post: 07-31-2011, 09:54 AM
  2. Replies: 8
    Last Post: 07-05-2011, 05:56 AM
  3. Update Database on Form Submit
    By Jordanx in forum AJAX
    Replies: 2
    Last Post: 06-17-2010, 01:33 PM
  4. IE8 & Opera 10 Form Submit Problem
    By FAMFred in forum PHP Development
    Replies: 1
    Last Post: 06-17-2010, 10:08 AM
  5. HTML Web Form Submit Button
    By amie654 in forum HTML Programming
    Replies: 2
    Last Post: 08-10-2008, 02:24 AM

Tags for this Thread

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