I am trying to get two resumes from a PHP form to my email ID. I am getting all information perfectly, but the attachments are coming blank. I could not find out the reason.

Any help will be appreciated. Please find below, both HTML and PHP codes. Thanks in advance.

<form name="Form5" method="post" enctype="multipart/form-data"  action="js/curent-job.php" onsubmit="return ValidateForm2()">
<table width="55%" align="left" cellpadding="0"  cellspacing="0">
<tr>
<td colspan="3" style="height:70px;">

<p>Please submit your updated resume with the below details. </p>

</td>
</tr>

<tr>
<td width="93"><label for="Full_Name" class="required">Name:</label></td>
<td width="40">&nbsp;</td>
<td width="252"><input name="Full_Name" id="Full_Name" maxlength="80" style="width: 250px; height:20px" type="text"></td>
</tr>

<tr style="height:5px">
<td colspan="3"></td>
</tr>

<tr>
<td><label for="Tel_No" class="required">Telephone:</label></td>
<td>&nbsp;</td>
<td><input name="Tel_No" id="Tel_No" maxlength="100" style="width: 250px; height:20px" type="text"></td>
</tr>

<tr style="height:5px">
<td colspan="3"></td>
</tr>

<tr>
<td> <label for="Email_Address" class="required">Email Id:</label></td>
<td>&nbsp;</td>
<td> <input name="Email_Address" id="Email_Address" maxlength="100" style="width: 250px; height:20px" type="text"></td>
</tr>

<tr style="height:5px">
<td colspan="3"></td>
</tr>

<tr>
<td> <label for="Resume" class="required">Resume 1:</label></td>
<td>&nbsp;</td>
<td> <input name="Resume" id="Resume" maxlength="100" type="file"></td>
</tr>


<tr>
<td> <label for="Resume2" class="required">Resume 2 :</label></td>
<td>&nbsp;</td>
<td> <input name="Resume2" id="Resume2" maxlength="100" type="file"></td>
</tr>

<tr style="height:5px">
<td colspan="3"></td>
</tr>

<tr>
<td><label for="Description" class="required">Description:</label></td>
<td>&nbsp;</td>
<td><textarea style="width: 250px; height: 60px;" name="Description" id="Description" maxlength="3000"></textarea></td>
</tr>

<tr style="height:5px">
<td colspan="3"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="image" src="images/button.png" width="75" height="30" /></td>
</tr>

</table>
</form>





<?php 

if(isset($_POST['Email_Address'])) {


    $files = array("Resume.docx", "Resume2.docx");

    $email_to = "abc@mydomain.com";
    $email_subject = "My Company - Career Enquiry";
    $thankyou = "http://www.mydomain.com/thanks.html";
    $email_sender = "admin@mydomain.com";

    // boundary
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 



    function died($error) {
        echo "Sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }


    $full_name = $_POST['Full_Name']; // required
    $email_from = $_POST['Email_Address']; // required
    $telephone = $_POST['Tel_No']; //required
    $comments = $_POST['Description']; // required


    $email_message = "Message details below.\r\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Full Name: ".clean_string($full_name)."\r\n";
    $email_message .= "Email: ".clean_string($email_from)."\r\n";
    $email_message .= "Contact Number: ".clean_string($telephone)."\r\n";
    $email_message .= "Message: ".clean_string($comments)."\r\n";


    // multipart boundary
$email_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" . $email_message . "\n\n";
$email_message .= "--{$mime_boundary}\n";

// preparing attachments
 for($x=0;$x<count($files);$x++){
    $file = fopen($files[$x],"rb");
    $data = fread($file,filesize($files[$x]));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $email_message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
    "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $email_message .= "--{$mime_boundary}\n";
}

$headers = 'From: '.$email_sender."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// headers for attachment
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
Member Avatar for LastMitch

but the attachments are coming blank. I could not find out the reason.

It's on the upload issue and the code you provide didn't show any upload code.

I think you need to find the path so when you attached the file on to the email it will attached the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.