Jump to content

PHP to send form as an attachment


ashlie

Recommended Posts

Heya

 

I'm fairly (er, very) new to PHP. I'm looking for a form that sends its information as an .txt attachment.

I know how to make a php that sends its information in the body - but haven't had much luck on finding information how to send it as an attachment.

 

Can it be done in php? If so, does anyone know how?

 

Thanks in advance :)

 

Ashlie

Link to comment
https://forums.phpfreaks.com/topic/37682-php-to-send-form-as-an-attachment/
Share on other sites

This should be around what you're trying to do

 

<?php

function new_file() {
	$cmd = $_POST['cmd'];
	$text = $_POST['data'];

	if ($text && $cmd == 'Post') {
		$dir = './files/';
		$filename = time() . '.txt';
		$newfile = $dir . $filename;
		$handle = fopen($newfile, 'a');
		fwrite($handle, $text);
		fclose($handle);
		return "<a href='$newfile'>$filename</a>";
	}
}


echo "<br>" . new_file();


?>
<form action="" method="post">
  <textarea name="data"></textarea>

  <input type="submit" name="cmd" value="Post">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.