I have the following code

How do i first edit this to take errors and also to be able to attach files.

<?php
//Gets these from page before
$mail_ref = $_GET['mail_ref'];
$mail_title = $_GET['mail_title'];
$mail_location = $_GET['mail_location'];

?>

<title>RFC Job Application</title>

<link rel='stylesheet' href='../../rfcStyle.css' type='text/css'>
</head>
<body bgcolor='#ffffff' leftMargin='0' topMargin='6' marginheight='0' marginwidth='0'>
<table cellspacing='0' border='2' cellpadding='0' align='center' width='620' bordercolor='#000080'>
  <tr>
    <td class=bar><table width='97%' align='center' cellspacing='0' cellpadding='0' border='0'>
      <tr>
        <td class='banner' nowrap>RFC Recruitment Group</td>
        <td class='banner' nowrap align='right'>Management & Professional Recruitment</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td><img src='../../images/titleRfc.gif' width='185' height='70'></td>
  </tr>
  <tr>
    <td class=title><img src='../../images/imgJobApplication.gif' width='295' height='33'></td>
  </tr>
  <tr>
    <td align='center'>


<!-- START OF FORM -->
	<form ACTION="sendmail.php" METHOD=POST align='center'>
	    <table cellspacing='2' cellpadding='2' border='0' width='100%' bgcolor=#ffffff>
      <tr class=content2>
        <td class='heading'>Ref No.</td> 
        <td class='heading'>Job Title</td> 
        <td class='heading'>Location</td> 
      </tr>
      <tr class=content2>
        <td><input name='mail_ref' value="<? echo $mail_ref ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
        <td><input name="mail_title" value="<? echo $mail_title ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
        <td><input name='mail_location' value="<? echo $mail_location ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
      </tr>
      <tr>
        <td colspan=3 class='title' height=20 valign='center' align='center'>Your Details&nbsp;&nbsp;&nbsp;&nbsp;<font class=content3>(* Required Information)</font></td>
      </tr>
      <tr>
        <td class='heading'><font class='content3'>*</font> Your Name</td>
        <td class='heading'>Email Address </td>
        <td class='heading'>Phone No.</td>
      </tr>
      <tr>
        <td><input name='mail_Name' tabindex='1' type='text' size='20' style='width: 180px; height: 22px;'></td>
        <td><input name='mail_Email' tabindex='2' type='text' size='20' style='width: 180px; height: 22px;'></td>
        <td><input name='mail_Tel' tabindex='3' type='text' size='20' style='width: 180px; height: 22px;'></td>
      </tr>
      <tr>
        <td class='heading'><font class='content3'>*</font> Contact Address</td>
        <td class='heading' colspan='2'>Additional Comments</td>
      </tr>
      <tr>
        <td>
		<textarea name='mail_Contact' tabindex='4' style='width: 180px;' cols='20' rows='4' wrap='physical'></textarea></td>
        <td colspan='2'><textarea name='mail_Comments' tabindex='5' rows='4' style='width: 360px;' cols='40'></textarea></td>
      </tr>
      <tr>
        <td colspan='3' align='center' valign='center' height='50'>&nbsp;
		</td>
      </tr>
      <tr>
        <td colspan='3' align='center' valign='center' height='50'><input name="submit" type='submit' tabindex='6' value=' Send Application '></td>
      </tr>
    </table>
    </form>
    </td>
  </tr>
  <tr>
    <td class=bar height='15' align='center'>
	<a class=headlink href='javascript:window.close();'>Close Window</a></td>
  </tr>
</table>
</body>
</html>
<?


//////////////////////////PAGE 2

//first_mail.php
$mail_to = "bla@bla.com";
//$mail_subject = "Hi there";

$mail_ref = $_POST['mail_ref']; //Subject
$mail_title = $_POST['mail_title']; //Job Title
$mail_location = $_POST['mail_location']; //Location 
$mail_Name = $_POST['mail_Name']; //Name
$mail_Email = $_POST['mail_Email']; //Email address
$mail_Tel = $_POST['mail_Tel'];  //Tel number
$mail_Contact = $_POST['mail_Contact']; //Contact details
$mail_Comments = $_POST['mail_Comments']; //Comments

///MAin Body :::
$mail_body = "Location: $mail_location \n Job Title: $mail_title \nName: $mail_Name \nEmail: $mail_Email \nTel: $mail_Tel \nContact: $mail_Contact \nComments: $mail_Comments \n";
?>

I am not going to fix your code for you.

If I do .. you will never learn anything form it.

But have a look at this:

How to add multiple attachment to an email:

An email can be split into many parts separated by a boundary followed by a Content-Type and a Content-Disposition.

The boundary is initialized as follows:
<?php
$boundary = '-----=' . md5( uniqid ( rand() ) );
?>

You can attach a Word document if you specify:
<?php
$message .= "Content-Type: application/msword; name=\"my attachment\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment; filename=\"$theFile\"\n\n";
?>

When adding a file you must open it and read it with fopen and add the content to the message:
<?php
$path = "whatever the path to the file is";
$fp = fopen($path, 'r');
do //we loop until there is no data left
{
       $data = fread($fp, 8192);
       if (strlen($data) == 0) break;
       $content .= $data;
     } while (true);
$content_encode = chunk_split(base64_encode($content));
$message .= $content_encode . "\n";
$message .= "--" . $boundary . "\n";
?>

Add the needed headers and send!
<?php
$headers  = "From: \"Me\"<me@here.com>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
mail('myAddress@hotmail.com', 'Email with attachment from PHP', $message, $headers);
?>

Finally, if you add an image and want it displayed in your email, change the Content-Type from attachment to inline:

<?php
$message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n";
?>

This should give you everything you need to fix your own issue.

Go on you know you want to fix it for me at least show me how to put one if statement in it to check if the fields are filled in properly.

Thank you

Thank you for your help got it done it was not that hard. :D

My Pleasure

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.