I am trying to create a script which takes file from the user, encode it in base64 and then forward it to an email as attachment with encoded file.
This is the code till now :
Client side :
<form action="send.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file">
<input type="submit" value="Submit" name='submit'>
</form>
PHP Script (send.php)
<?php
$uploaded_file = basename($_FILES['uploaded_file']['name']);
$file_size = filesize($uploaded_file);
$handle = fopen($uploaded_file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content1 = base64_encode($content);
$my_file = "'$encoded_file' . '_encoded' . '.html'";
$handle1 = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
fwrite($handle1, $content1);
$from="tes@gmail.com";
$to="myemail@gmail.com"
$subject="New file";
$message="you got a new file";
mail($from,$to,$subject,$message);
unlink($my_file);
?>
I don’t know how to attach $myfile in the email.
If you’re not using any external mail libraries such as PEAR::SMTP or Swift then creating the attachments is not a simple thing.
You will have to check the mail standards they instruct on how to separate the headers from the message content and the message content from the attachments.
The separator is
\r\nand each section must be preceded by a separator.Check this link out: http://webcheatsheet.com/php/send_email_text_html_attachment.php
And my code example: