I have this form to send an email and the visitor can send an attachment with his email as will everything gos well the email sent but the attachment comes to the email like this

 if he uploaded any C.V the C.V will be attached to this Email --_1_c4fe3315ccb7d6076c71d64ec5265ecc Content-Type: multipart/alternative; boundary="_2_c4fe3315ccb7d6076c71d64ec5265ecc"

    --_2_c4fe3315ccb7d6076c71d64ec5265ecc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit

    --_2_c4fe3315ccb7d6076c71d64ec5265ecc-- --_1_c4fe3315ccb7d6076c71d64ec5265ecc Content-Type: application/octet-stream; name="Yousef.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment

    --_1_c4fe3315ccb7d6076c71d64ec5265ecc--

this is my php code to send my email

<?php
error_reporting(E_ALL | E_STRICT);
if (isset($_POST['submit'])) {
    $sector = $_POST['cSector'];
    $cAdministration = $_POST['cAdministration'];
    $cBranch = $_POST['cBranch'];
    $cCareer = $_POST['cCareer'];
    $name = $_POST['cName'];
    $telephone = $_POST['cTelephone'];
    $cEmail = $_POST['cEmail'];
    $cMessage = $_POST['cMessage'];

    $recipient = 'info@test.com';
    $subject = "Someone apply for career";

    $myCv = $_FILES['upFile']['name'];
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['upFile']['tmp_name'])));
    $boundary = md5(date('r', time()));

    $content = "This information is for someone who apply for your new career\n
    Sector Applied For:" . $sector . ",\n
    Administration Applied For:" . $cAdministration . ",\n
    Branch Applied For:" . $cBranch . ",\n
    Career Applied For:" . $cCareer . ",\n
    His Name Is: " . $name . ",\n
    His Phone Number: " . $telephone . ",\n
    His Message: " . $cMessage . ",\n
    His Email: " . $cEmail . ",\n if he uploaded any C.V the C.V will be attached to this Email
    --_1_$boundary
    Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

    --_2_$boundary
    Content-Type: text/plain; charset=\"UTF-8\"
    Content-Transfer-Encoding: 7bit

    --_2_$boundary--
    --_1_$boundary
    Content-Type: application/octet-stream; name=\"$myCv\"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment

    $attachment
    --_1_$boundary--";

    $headers = "From:info@test.com\r\nReply-To:info@test.com";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $sent = mail($recipient, $subject, $content, $headers);
    if ($sent) {
        header("Location:index.php?pid=17&carr=your message has been sent, we will contact you soon.");
    } else {
        echo "Error";
    }
}
?>

Now I understood the problem, but still can not solve it completely.
the problem was in the space putting extra space for content-type declaration code in His mail:
now when I remove the extra space the attach go right but the email body never come it come like the email just has an attach only
can anybody help me with that

thanks

i hope this will help u.try this

if($_SERVER['REQUEST_METHOD'] == 'POST')
{

$from = $_POST['email'];
$name = $_POST['name'];

$subject = "test";
            $message = 'From: ' . $from . "\r\n";
            $message .= "Name : $name\n\n";
            $message .= "Resume : $file";


// Obtain file upload vars
$fileatt = $_FILES['file']['tmp_name'];
$fileatt_type = $_FILES['file']['type'];
$fileatt_name = $_FILES['file']['name'];

$headers = "From: $from";

if (is_uploaded_file($fileatt)) {
  // Read the file to be attached ('rb' = read binary)
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);

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

  // Add the headers for a file attachment
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";

  // Add a multipart boundary above the plain message
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type:text/html;charset=utf-8" .
             "Content-Transfer-Encoding: 7bit\n\n" .
             $message . "\n\n";

  // Base64 encode the file data
  $data = chunk_split(base64_encode($data));

  // Add file attachment to the message
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .
              "--{$mime_boundary}--\n";
}

// Send the message
$ok = @mail($to, $subject, $message, $headers);
}
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.