stuck on this one :confused:
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.
php submit form to .txt file
Started by ferreirawebs, Jan 21 2010 07:57 AM
8 replies to this topic
#1
Posted 21 January 2010 - 07:57 AM
|
|
|
#2
Posted 21 January 2010 - 08:06 AM
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
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
I study Information Systems at Karlstad University when I'm not on CodeCall
#3
Posted 21 January 2010 - 08:26 AM
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?
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
Posted 21 January 2010 - 08:38 AM
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
I study Information Systems at Karlstad University when I'm not on CodeCall
#5
Posted 21 January 2010 - 11:09 AM
Orjan said:
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
Posted 21 January 2010 - 12:06 PM
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.
I found an example online.
<?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
Posted 22 January 2010 - 01:27 AM
hi! I am a newbie... I have a small doubt.....Why PHP Submit form to .txt file...?
#8
Posted 22 January 2010 - 08:37 AM
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?
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?
BlaineSch said:
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.
I found an example online.
<?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
Posted 28 January 2010 - 03:34 AM
hi, thanks a lot to ur Reply.....


Sign In
Create Account

Back to top










