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";
?>
Attachments
<?php

//$mail_ref = "BLA";
//$mail_title = "BAL2";
//$mail_location = "BLA3";
$mail_ref = $_GET['mail_ref'];
$mail_title = $_GET['mail_title'];
$mail_location = $_GET['mail_location'];

//function Apply(ref,title,location){
//var a= window.open("","a","width=650,height=450,resizable=yes,status=no,menubar=no,toolbar=no,directories=no,location=no,left=20,top=20
//<html>
//<head>
//<script language='javascript' src='../js/validate.js'></script>
?>

<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>
<?

//first_mail.php
$mail_to = "namit@eircom.net";
//$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";

//echo "$mail_ref<br>";
//echo "$mail_title<br>";
//echo "$mail_location<br>";
//echo "$mail_Name<br>";
//echo "$mail_Email<br>";
//echo "$mail_Tel<br>";
//echo "$mail_Contact<br>";
//echo "$mail_Comments<br><br>";

//Main Body
//echo "$mail_body";

if(mail($mail_to, $mail_ref, $mail_body))
	echo "<br>Successfully sent emial \"$mail_ref\" to $mail_to.";
else echo "Failded to send";

?>

<html>
<head>
<title>RFC Acknowledgement</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 class='title' height='20' valign='center' align='center'>Acknowledgement</td>
   </tr>
  <tr>
    <td class=content height='260' valign='center' align='center'>Thank you for your Job Application. We
    will contact you shortly.</td>
   </tr>
  <tr class=bar>
    <td class=banner height='15' align='center'><a class=headlink href='javascript:window.close();'>Close Window</a></td>
  </tr>
</table>
</body>
</html>

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

This article has been dead for over six months. Start a new discussion instead.