EDIT: If this is possible is it also possible to store the information in a way that all variables can be saved to be recalled by a separate form.
PHP Sendmail......8O
Moderator: General Moderators
PHP Sendmail......8O
Hey, I appologize in advance, I'm quite noob to PHP, working on a form that emails information, well have that working properly right now, but I'm trying to have the information stored in a TXT file and that file emailed to me as an attachment. It sounds possible, any help would be great. Thanks in advance. 
EDIT: If this is possible is it also possible to store the information in a way that all variables can be saved to be recalled by a separate form.
EDIT: If this is possible is it also possible to store the information in a way that all variables can be saved to be recalled by a separate form.
This is a good tutorial: http://www.tutorialized.com/view/tutori ... ents/24317
Please Help.
Got the text document formatted in a way that is acceptable for now, now im faced with attaching it to the sendmail function so that It can be retrived. heres what I have for my code thus far.
Code: Select all
<?php
// Read POST request params into global vars
$to = "me@example.com"
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Obtain file upload vars
$fileatt = (file_get_contents('D0K341_.dat'));
$headers = "From: $from";
$file = fopen($fileatt);
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$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/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain;\n" .
" name=\"D0K341_.dat\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"D0K341_.dat\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>