Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8995711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:39:22+00:00 2026-06-15T23:39:22+00:00

I am trying to create a script which takes file from the user, encode

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:39:22+00:00Added an answer on June 15, 2026 at 11:39 pm

    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\n and 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:

    $uid = md5(uniqid(time()));
    $header = implode("\r\n",
        array(
            'MIME-Version: 1.0',
            'From: Address <address@example.com>',
            'Reply-To: Address <address@example.com>',
            'Cc: Address <address@example.com>',
            'Content-Type: multipart/mixed;',
            '    boundary="'.$uid.'"',
            '',
            '--'.$uid,
            'Content-Type: text/plain;',
            '    charset="us-ascii"',
            'Content-Transfer-Encoding: 7bit',
            '',
            mb_convert_encoding(
                implode("\r\n",
                    array_map('wordwrap',
                        array(
                            'Hello,',
                            '',
                            'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet varius augue non pretium. Nullam dignissim iaculis velit, ut cursus neque mollis et. Fusce faucibus dictum nunc, sit amet cursus tellus aliquam ut. Praesent id libero orci, ut vehicula orci. Proin nulla sem, dapibus in lacinia vel, pharetra eget eros. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras rhoncus, enim sed mollis suscipit, sapien mauris suscipit mauris, nec placerat nisi sapien ac lectus. Sed vehicula faucibus iaculis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer placerat commodo nibh. Morbi sit amet augue vitae urna mattis pulvinar ac eget tellus. Donec mattis cursus posuere. Donec dolor velit, aliquam eu pretium vel, accumsan eu est. Proin at ante nisi, ut malesuada diam.',
                            '',
                            'Nulla ac urna lacus, in luctus ipsum. Nunc luctus risus non dui tincidunt in ultricies tellus rhoncus. Aliquam pellentesque vehicula adipiscing. Phasellus porttitor sodales quam et cursus. Pellentesque iaculis consectetur lorem, et consectetur sem tristique sed. Duis vehicula eleifend nisl, a semper augue lobortis cursus. Fusce ut ligula diam. Quisque fringilla sodales massa vitae rhoncus. Pellentesque a libero sed enim lacinia commodo quis et dolor. Praesent facilisis, orci nec lacinia ultrices, enim nunc imperdiet augue, at aliquet dolor augue nec nulla.',
                            '',
                            'Ut venenatis commodo pulvinar. Vestibulum quam odio, malesuada posuere porttitor facilisis, molestie vel risus. Mauris auctor fringilla ornare. Morbi eu libero orci, nec semper lorem. Quisque blandit, ante nec pharetra bibendum, felis felis tincidunt felis, sed mattis sapien lorem et risus. In sed interdum quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas vitae metus id purus ultrices fermentum. In dui eros, feugiat sit amet feugiat vel, accumsan vitae ligula. Nam at consectetur elit. Maecenas eget metus id nibh luctus mattis. Quisque mollis, sapien semper vulputate venenatis, purus arcu ornare orci, sit amet pellentesque enim ipsum non urna. Quisque at augue nec quam vehicula suscipit eu a dui. Morbi at molestie nunc. Mauris ultricies rutrum euismod. Sed non sem nisi. '
                        )
                    )
                ),
                'iso-8859-1'
            ),
            '',
            '--'.$uid,
            'Content-Type: application/pdf;',
            '    name="file.pdf"',
            'Content-Transfer-Encoding: base64',
            'Content-Disposition: attachment;',
            '    filename="file.pdf"',
            '',
            chunk_split(base64_encode(file_get_contents('file.pdf'))),
            '--'.$uid.'--'
        )
    );
    mail($contacts, 'Subject', '', $header);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a Python script which takes a special type of file
I am trying to create a Mathematica script which takes as input a function
im trying to create a script that opens a file and replace every 'hola'
I'm trying to create simple script that subscribes a user to a company calendar.
I'm loading a dynamic application (which takes 20-30 seconds), and I'm trying to create
I'm trying to run a script that takes a text file, compresses it using
I'm trying to create a script/application which accepts command line arguments when run. Of
Before I start, I am trying to create a python zip script which will
I am trying to create a script that takes a $$variable and adds them
I am trying to create a Python script which will take an address as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.