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 8489893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:57:14+00:00 2026-06-10T21:57:14+00:00

i have a form where i have an input file to place an attachment.

  • 0

i have a form where i have an input file to place an attachment. It happens that all the data i have in the form i want to send by email. However, before i do that, i redirect all the data inputed to another php page and receive it with get.

So my first question is, how can i get the content of the attachment in other php page by get?

After that, after i verify all the data in the new php page, i pretend to send it by email. I plan to use this code:

    //define the receiver of the email 
$to = 'myemail@something.com'; 
//define the subject of the email 
$subject = 'Test email with attachment'; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash 
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n 
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; 
//add boundary string and mime type specification 
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip'))); 
//define the body of the message. 
ob_start(); //Turn on output buffering 
?> 
--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

Hello World!!! 
This is simple text email message. 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2> 
<p>This is something with <b>HTML</b> formatting.</p> 

--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: application/zip; name="attachment.zip"  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment  

<?php echo $attachment; ?> 
--PHP-mixed-<?php echo $random_hash; ?>-- 

<?php 
//copy current buffer contents into $message variable and delete current output buffer 
$message = ob_get_clean(); 
//send the email 
$mail_sent = @mail( $to, $subject, $message, $headers ); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 

But i have a doubt, where there is “attachment.zip” what should i put? The variable that will get the data of the attachment on this new php page?

Thanks in advance!

Forgetting the part above:

this is my declaration and submit button on the form:

<form id="formElem" name="formElem" enctype="multipart/form-data" action="" method="post">

<button name='enviar_candidatura' id='enviar_candidatura' value='enviar_candidatura' onclick='return false;' type='submit'>

when i click on the button above, i enter on the following jquery function:

$('#enviar_candidatura').bind('click',function(){

    var conta_Duplicates;
    conta_Duplicates=dadosImportantes();
    //alert("Deu");
    var preenchimentoForm=true;
    //alert("Contasssss"+conta1);
    //var eventos=$countEventos;
    var eventos=conta_Duplicates[2];
    //alert("Wiggins"+eventos);
    //var empregos=$countEmpregos;
    var empregos=conta_Duplicates[1];
    //var cursos=$countCursos;
    var cursos=conta_Duplicates[0];

    //alert($countEmpregos);
    if($('#formElem').data('errors')){
        preenchimentoForm=false;

        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
        return false;
    }
    else{
        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
    }
}

That’s in this function i’m having difficult, because if i’m right, i should have a var here assigned to the form element so that i can pass her to the function “dadosFormularios”.

Once inside the dadosFormularios(…), it’s there i want to call the

form.action = 'index.php?pagina=candidaturasB&'+ qstringA;

to redirect to the php page where i will send the email with the attachment.

Hope i was clear and sorry for some variables in a foreign language, hope it’s not a problem.

  • 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-10T21:57:16+00:00Added an answer on June 10, 2026 at 9:57 pm

    The form you are completing needs to have enctype="multipart/form-data" and needs to have method="post" for upload to work.

    like this:

    <form method="post" action="" enctype="multipart/form-data" id="myform" onsubmit="return checkForm(this)";>
        <input type="file" name="filename" />
        // ...........
    </form>
    

    After that in your send mail you can get the file with $_FILES['filename']['tmp_name'], notice that filename has to be same as input’s name:

    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['filename']['tmp_name'])));
    

    for function

    <script type="text/javascript">
        function checkForm(form){
            // process fieds
            return checkNextFunction(form);
        }
    
        function checkNextFunction(form){
             form.action = 'myurl.php';
             return true;
        }
    </script>
    

    Check JSFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have a php file that contains a form (which contains 2 input boxes
if i have one form that include some input, textarea, select, and multiple file.
Is it possible to reload a form after 'file-input' change? I have a form
I have in my form an input element with type of file. What I
I have a asp.net form with 5 HTML file input controls with runat=server and
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
I have an upload box... <form action=upload_file.php method=post enctype=multipart/form-data><BR> <label for=file>Filename:</label><BR> <input type=file name=file
I have a form input in my application that accepts dates in the format
Imagine this simple form for uploading a file: <form action=upload enctype=multipart/form-data> <input type=text name=name/>

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.