title: Sending an uploaded file as attachment to email
body: <p>I am a novice in Web designing. I need to create a form in HTML such that it asks the user to enter several fields and upload his/her resume. When he submits the form, his submissions should be email to me with his resume as the attachment with the email.
  I have used PHP for sending the email. Everything works fine, except that the file is not getting attached with the sent email.</p>
  
  <p>I am posting both the HTML and the PHP code, please help me..</p>
  
  <p><strong>HTML Code: FileName: Careers.html</strong></p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Contact Form&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="Careers.php" method="post" enctype="multipart/form-data"&gt;
      Name&lt;br&gt;
       &lt;input type="text" name="cf_name"&gt;&lt;br&gt;
      E-mail&lt;br&gt;
       &lt;input type="text" name="cf_email"&gt;&lt;br&gt;
          Date of Birth&lt;br&gt;
       &lt;input type="text" name="db_name"&gt;&lt;br&gt;
          Contact Number&lt;br&gt;
       &lt;input type="text" name="db_cntct"&gt;&lt;br&gt;
      Class 12 Marks/CGPA/Percentage&lt;br&gt;
       &lt;input type="text" name="cf_board"&gt;&lt;br&gt;
           Graduation Marks/CGPA/Percentage&lt;br&gt;
       &lt;input type="text" name="db_grad"&gt;&lt;br&gt;
       Post-Graduation Marks/CGPA/Percentage&lt;br&gt;
       &lt;input type="text" name="cf_pgrad"&gt;&lt;br&gt;
          Present Employer&lt;br&gt;
       &lt;input type="text" name="db_emplyr"&gt;&lt;br&gt;
       Date of Joining&lt;br&gt;
       &lt;input type="text" name="cf_doj"&gt;&lt;br&gt;
          Designation&lt;br&gt;
       &lt;input type="text" name="db_desg"&gt;&lt;br&gt;
          Current CTC&lt;br&gt;
       &lt;input type="text" name="db_ctc"&gt;&lt;br&gt;
       Upload your Resume&lt;br&gt;
       &lt;input type="file" name="attachment" size="40"&gt;&lt;br&gt;
  Message&lt;br&gt;
  &lt;textarea name="cf_message"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="Send"&gt;
  &lt;input type="reset" value="Clear"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>PHP Code: FileName: Careers.php</strong></p>
  
  <pre><code>&lt;?php
  $field_name = $_POST['cf_name'];
  $field_email = $_POST['cf_email'];
  $field_dob = $_POST['db_name'];
  $field_contact = $_POST['db_cntct'];
  $field_board = $_POST['cf_board'];
  $field_grad = $_POST['db_grad'];
  $field_pgrad = $_POST['cf_pgrad'];
  $field_emplyr = $_POST['db_emplyr'];
  $field_doj = $_POST['cf_doj'];
  $field_desg = $_POST['db_desg'];
  $field_ctc = $_POST['db_ctc'];
  $field_message = $_POST['cf_message'];
  
  $mail_to = 'sachinrocksus@gmail.com';
  $subject = 'Job Application from a site visitor '.$field_name;
  
  $body_message = 'From: '.$field_name."\n";
  $body_message .= 'E-mail: '.$field_email."\n";
  $body_message .= 'Date of Birth: '.$field_dob."\n";
  $body_message .= 'Contact Number: '.$field_contact."\n";
  $body_message .= 'Class 12 Marks/CGPA/Percentage: '.$field_board."\n";
  $body_message .= 'Graduation Marks/CGPA/Percentage: '.$field_grad."\n";
  $body_message .= 'Post-Graduation Marks/CGPA/Percentage: '.$field_pgrad."\n";
  $body_message .= 'Present Employer: '.$field_emplyr."\n";
  $body_message .= 'Date of Joining: '.$field_doj."\n";
  $body_message .= 'Designation: '.$field_desg."\n";
  $body_message .= 'Current CTC: '.$field_ctc."\n";
  $body_message .= 'Message: '.$field_message."\n";
  
  $headers = 'From: '.$field_email."\r\n";
  $headers .= 'Reply-To: '.$field_email."\r\n";       
  
  $mail_status = mail($mail_to, $subject, $body_message, $headers);
  
  if ($mail_status) { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Your Job Application has been recieved. We will contact you shortly.');
          window.location = 'Careers.html';
      &lt;/script&gt;
  &lt;?php
  }
  else { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Message failed');
          window.location = 'Careers.html';
      &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>