i have got this done so far but it still isn't working properly its really doing my head in it sends the message fine subject file attachment but cuts the html message off halfway down and doesn't send the disclaimer if i change $message which is being passed to $messagemain it sends me a message with the disclaimer but no attachment. I have almost got it right but not quite ???
Also if no file is attched it doesn't send anything.

html

<?php
$random = rand(100,999);
?>

<form name="careers" enctype="multipart/form-data" method="post" action="submit/submitcareers.php" onsubmit="return v.exec()">
<table class="form">

<tr><td colspan="2">
<input type="hidden" name="subject" value="Employment Application" />
<input type="hidden" name="random" value="<?=$random?>"> 
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"> 
</td></tr>

<tr><td class="head"><span id="t_fname">FIRSTNAME</span></td>
<td class="head"><span id="t_lname">LASTNAME</span></td></tr>
<tr><td class="name"><input type="text" name="firstname" /></td><td class="name"><input type="text" name="lastname" /></td></tr>

<tr><td class="head"><span id="t_email">EMAIL</span></td>
<td class="head"><span id="t_telephone">TELEPHONE</span></td></tr>
<tr><td class="email"><input type="text" name="email" /></td><td class="telephone"><input type="text" name="telephone" /></td></tr>

<tr><td colspan="2" class="head"><span id="t_country">COUNTRY</span></td></tr>
<tr><td colspan="2" class="country"><input type="text" name="country" /></td></tr>

<tr><td class="head"><span id="t_position">POSITION APPLIED FOR</span></td>
<td class="head">&nbsp;</td></tr>
<tr><td class="name"><input type="text" name="position" /></td><td class="name">&nbsp;</td></tr>

<tr><td colspan="2" class="head"><span id="t_message">WHY DO YOU THINK YOU WOULD BE AN ASSET TO OUR TEAM?</span></td></tr>
<tr><td colspan="2" class="message"><textarea  name="message"></textarea></td></tr>

<tr><td colspan="2" class="head">CURRICULUM VITAE</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt" /></td></tr>

<tr><td colspan="2" class="head"><span id="t_validate">CONFIRMATION NUMBER</span></td></tr>
<tr><td colspan="2" class="validate"><span class="validatebox"><?=$random?></span><input type="text" name="validate" maxlength="3" /></td></tr>

<tr><td colspan="2">&nbsp;</td></tr>

</tr><td class="submit" colspan="2"><input name="submit" type="submit" value="Submit" /></td></tr>
</tr><td class="submit" colspan="2"><input name="reset" type="reset" value="Reset" /></td></tr>

<tr><td colspan="2">&nbsp;</td></tr>
</table>
</form>

</td>
</tr>
</table>

php submit

<? 
ini_set ("display_errors", "1");
error_reporting(E_ALL);

	$subject		= ($_POST['subject']);
	$firstname 		= ($_POST["firstname"]);
	$lastname 		= ($_POST["lastname"]);
	$email		= ($_POST['email']);
	$telephone		= ($_POST["telephone"]);
	$country		= ($_POST["country"]);
	$position		= ($_POST["position"]);
	$message		= ($_POST['message']);
	$random		= ($_POST['random']);
	$validate		= ($_POST['validate']);
      $fileatt      = $_FILES['fileatt']['tmp_name'];
      $fileatt_type = $_FILES['fileatt']['type'];
      $fileatt_name = $_FILES['fileatt']['name'];


if ($random==$validate)

{
  
header("Location:thankyou.php?message=careers");




if (is_uploaded_file($fileatt)) {
   $file = fopen($fileatt,'rb');
   $data = fread($file,filesize($fileatt));
   fclose($file);

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

$to = "info@website.com";
$headers = "From: noreply@website.com";  
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

$message .= "\n\n";
$message .= "--{$mime_boundary}\n";
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$message .= "
<html>
<head>
<title>HTML message</title>
</head>
<body>
<table>
<tr><td align='left'><img src='http://www.website.com/pix/logo.gif'></td></tr>
</table>
<table style='padding-left:20px'>
<tr><td>&nbsp;</td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>FIRSTNAME: $firstname</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>LASTNAME: $lastname</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>EMAIL: $email</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>TELEPHONE: $telephone</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>COUNTRY: $country</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>POSITION: $position</font></td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>REASON: $message</font></font></td></tr>
<tr><td>&nbsp;</td></tr>
</table>
<table>
<tr><td><font style='font-size: 10px' style='font-family: Tahoma, Arial'>This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. 
If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. 
If you have received this communication in error, please destroy this message. 
Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity. 
</font></td></tr>
</table>
</body>
</html>";


$data = chunk_split(base64_encode($data));


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


}


mail($to, $subject, $message, $headers);



		exit;
}

else

{


		header("Location:thankyou.php?message=invalid");
		exit;
}
?>

I would recommend PHPMailer or SwiftMailer for this task.

Both handle attachments and html emails etc seamlessly, but both are also much more frequently udpated/patched etc.

mm i already have pear on my server but have never used it
but from loooking at this

$mime->addAttachment($file, 'text/plain');

looks like i can only define one type of file attachment my users could be uploading text iage doc xls or pdf files??

got it working now with or without attachments but is there anything i can add to this to disallow .exe files being attached?

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);

$subject = $_POST['subject'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$country = $_POST['country'];
$position = $_POST['position'];
$textmessage = $_POST['message'];
$ipaddress = $_POST['ipaddress'];
$random = $_POST['random'];
$validate = $_POST['validate'];
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

if($random == $validate)
{

        $to = 'info@website.com';
        $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
        // headers
        $headers = "From: noreply@website.com\n";  
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
        // message
        $message = "--{$boundary}\n";
        $message .= "Content-Type: text/html; charset=iso-8859-1\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "<html>
<head>
<title>HTML message</title>
</head>
<body>
<table>
  <tr><td><img src=\"http://www.website.com/pix/logo.gif\"></td></tr>
</table>
<table style=\"padding-left: 20px;\">
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">FIRSTNAME: $firstname</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">LASTNAME: $lastname</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">EMAIL: $email</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">TELEPHONE: $telephone</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">COUNTRY: $country</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">POSITION: $position</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">REASON: $textmessage</td></tr>
  <tr><td style=\"font-size: 13px; font-family: tahoma, san-serif;\">IP ADDRESS: $ipaddress</td></tr>
</table>
<table>
  <tr><td style=\"font-size: 10px; font-family: tahoma, san-serif;\">This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. 
If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. 
If you have received this communication in error, please destroy this message. 
Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity.</td></tr>
</table>
</body>
</html>
";

    if(is_uploaded_file($fileatt))
    {
        // attachment
        $fp = fopen($fileatt, 'rb');
        $data = fread($fp, filesize($fileatt));
        fclose($fp);

        $data = chunk_split(base64_encode($data));
        $message .= "--{$boundary}\n";
        $message .= "Content-Type: $fileatt_type;\n name=\"$fileatt_name\"\n";
        //$message .= "Content-Disposition: attachment;\n filename=\"$fileatt_name\"\n";
        $message .= "Content-Transfer-Encoding: base64;\n\n$data\n\n";
        $message .= "--{$boundary}--\n";
     }
        mail($to, $subject, $message, $headers);
        header("Location: thankyou.php?message=careersyes");
        exit;
    
}
else
{
    header("Location: thankyou.php?message=careersno");
    exit;
}
?>
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.