Page 1 of 1

Recaptcha - Form file attachment

Posted: Tue Dec 21, 2010 6:29 am
by mkoopa
Hi,

Could someone please help me with Recaptca? I have no experience with PHP, but have managed to get Recaptcha working on my site. I am using it for verification on a job application form. The verification works and sends the user to a success php page if they enter the code correctly, the success php page then emails the form details, this all works without an issue.

The problem I have is, there is a data element in my form that can be used to attach a cv. I would like the php code to attach the file to the email.

The code used for my form is below:

<form id="form1" name="form1" method="post" action="applicationsuccess.php">
<table width="97%" border="0">
<tr>
<td colspan="2" class="bodyfont">Personal Information</td>
<td colspan="2" class="bodyfont">Education History</td>
</tr>
<tr>
<td width="18%" class="bodyfont">Position Applied for:</td>
<td width="24%"><label>
<select name="position" id="position">
<option>Logistics</option>
<option>Maintenance</option>
<option>Production</option>
<option>Quality</option>
</select>
</label></td>
<td width="15%" class="bodyfont">Uni/College:</td>
<td width="43%" class="bodyfont"><label>
<input type="text" name="uni" id="uni" />
</label></td>
</tr>
<tr>
<td class="bodyfont">First Name:</td>
<td><label>
<input type="text" name="first name" id="first name" />
</label></td>
<td class="bodyfont">Qualifications</td>
<td rowspan="3" class="bodyfont"><label>
<textarea name="qualifications1" id="qualifications1" cols="45" rows="8"></textarea>
</label></td>
</tr>
<tr>
<td class="bodyfont">Surname:</td>
<td><label>
<input type="text" name="surname" id="surname" />
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">Address:</td>
<td><label>
<textarea name="address" rows="5" id="address"></textarea>
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">Postcode:</td>
<td><label>
<input type="text" name="postcode" id="postcode" />
</label></td>
<td class="bodyfont">Secondary School</td>
<td class="bodyfont"><label>
<input type="text" name="school" id="school" />
</label></td>
</tr>
<tr>
<td class="bodyfont">Telephone:</td>
<td><label>
<input type="text" name="tel" id="tel" />
</label></td>
<td class="bodyfont">Qualifications</td>
<td rowspan="5" class="bodyfont"><label>
<textarea name="qualifications2" id="qualifications2" cols="45" rows="8"></textarea>
</label></td>
</tr>
<tr>
<td class="bodyfont">Mobile:</td>
<td><label>
<input type="text" name="mobile" id="mobile" />
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">Email:</td>
<td><label>
<input type="text" name="email" id="email" />
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">Date of Birth</td>
<td><label>
<input type="text" name="dob" id="dob" />
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">National Insurance No:</td>
<td><label>
<input type="text" name="national insurance" id="national insurance" />
</label></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td class="bodyfont">Attach CV:</td>
<td><input name="cv" type="file" value="" size="10" maxlength="100" id="cv">&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
<td rowspan="5" class="bodyfont"><?php
require_once('recaptchalib.php');
$publickey = "my public key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="left"><input type="submit" name="submit" id="submit" value="SUBMIT" /></td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
<td class="bodyfont">&nbsp;</td>
</tr>
</table>
</form>






The code that I am using on the success page to send the form data is below.

<?php
require_once('recaptchalib.php');
$privatekey = "my private key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if(!$resp->is_valid) {
header("location:captcha_error.php");
die();
}
?>

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Refresh: 0; URL=/index.html');
exit;
}

$mailto = "email@ourcompany.com";
$subject = "Job Application";
$message = "Query / Comments";
$name = Valid_Input($_POST['name']);
$email = Valid_Email($_POST['email']);
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;
}
}
}
$header = "From: ".$name." <".$email.">\n";
$header .= "Reply-To: ".$email."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 8bit\n";
$header .= "X-Mailer: PHP v".phpversion();

mail($mailto, $subject, stripslashes($message), $header) or exit('Fatal Mail Error!');

function Valid_Input($data){
list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data));
return $data;
}
function Valid_Email($data){
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
if (preg_match($pattern,$data)){
return $data;
}
else{
return $GLOBALS['mailto'];
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
window.onload = function() {
/* set your parameters(
number to countdown from,
pause between counts in milliseconds,
function to execute when finished
)
*/
startCountDown(5, 1000, myFunction);
}

function startCountDown(i, p, f) {
// store parameters
var pause = p;
var fn = f;
// make reference to div
var countDownObj = document.getElementById("countDown");
if (countDownObj == null) {
// error
alert("div not found, check your id");
// bail
return;
}
countDownObj.count = function(i) {
// write out count
countDownObj.innerHTML = i;
if (i == 0) {
// execute function
fn();
// stop
return;
}
setTimeout(function() {
// repeat
countDownObj.count(i - 1);
},
pause
);
}
// set it going
countDownObj.count(i);
}

function myFunction() {
;
}
</script>
<meta http-equiv="refresh" content="5; url=http://www.futabaindustrialuk.co.uk/index.html">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FIUK APPLICATION SUCCESS</title>
<style type="text/css">
<!--
-->
</style>
<link href="center_browser.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-image: url(images/bg_greengrad.jpg);
}
#apDiv4 {
position:absolute;
left:1px;
top:129px;
width:386px;
height:37px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
visibility: visible;
}
#apDiv3 {
position:absolute;
left:2px;
top:171px;
width:975px;
height:200px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv2 {
position:absolute;
left:2px;
top:120px;
width:975px;
height:112px;
border:1px none #000000;
z-index:1;
}
#apDiv1 {
position:absolute;
left:2px;
top:5px;
width:975px;
height:226px;
background-image:url(images/fut1.png);
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv5 {
position:absolute;
left:591px;
top:129px;
width:386px;
height:37px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv6 {
position:absolute;
left:1px;
top:376px;
width:975px;
height:26px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
background-image: url(images/header.png);
}
#apDiv7 {
position:absolute;
left:400px;
top:378px;
width:206px;
height:22px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv8 {
position:absolute;
left:2px;
top:408px;
width:394px;
height:334px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
background-image: url(images/contact.png);
}
#apDiv9 {
position:absolute;
left:683px;
top:417px;
width:318px;
height:321px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv10 {
position:absolute;
left:1px;
top:751px;
width:976px;
height:44px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
background-image: url(images/footer.png);
}
#apDiv11 {
position:absolute;
left:15px;
top:441px;
width:368px;
height:290px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
#apDiv12 {
position:absolute;
left:0px;
top:408px;
width:975px;
height:334px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
background-image: url(images/application2.png);
}
#apDiv13 {
position:absolute;
left:14px;
top:445px;
width:549px;
height:291px;
layer-background-image:url(/images/bg.jpg);
border:1px none #000000;
z-index:1;
}
a:link {
color: #FFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #060;
}
a:hover {
text-decoration: none;
color: #11922E;
}
a:active {
text-decoration: none;
}

-->
</style><script type="text/javascript" src="stmenu.js"></script></head>

<body>
<div id="wrapper">
<div id="apDiv1"></div>
<div id="apDiv2"><img src="images/line.png" alt="" name="curved_line" width="975" height="111" id="curved_line" /></div>
<div id="apDiv3"><img src="images/plant.png" alt="" name="plant" width="975" height="200" id="plant" /></div>
<div id="apDiv4">
<script type="text/javascript">
<!--
stm_bm(["menu2215",900,"","blank.gif",0,"","",0,0,250,0,1000,1,0,0,"","",0,0,1,2,"default","hand","",1,25],this);
stm_bp("p0",[0,4,0,0,0,7,31,7,100,"",-2,"",-2,50,0,0,"#999999","transparent","bg_01.gif",3,1,1,"#000000"]);
stm_ai("p0i0",[0,"FIUK LTD","","",-1,-1,0,"","_self","","","","",31,5,0,"arrow_r.gif","arrow_r.gif",7,7,0,1,1,"#FFFFF7",1,"#993333",1,"bg_06_edit_down.gif","bg_06_edit.gif",3,1,7,1,"#000000","#000000","#009900","#FFFFFF","bold 9pt Arial","bold 9pt Arial",0,0,"","","","",0,0,0]);
stm_bpx("p1","p0",[1,4,0,0,0,7,39,0]);
stm_aix("p1i0","p0i0",[0,"HOME","","",-1,-1,0,"index.html","_self","","","","",39,5,0,"","",0,0,0,2]);
stm_aix("p1i1","p1i0",[0,"PROFILE","","",-1,-1,0,"profile.html","_self","","","","",14]);
stm_aix("p1i2","p0i0",[0,"OVERVIEW","","",-1,-1,0,"overview.html","_self","","","","",0,5,0,"","",0,0]);
stm_aix("p1i3","p1i0",[0,"HISTORY","","",-1,-1,0,"history.html","_self","","","","",0]);
stm_ep();
stm_aix("p0i1","p0i0",[0,"WHAT WE DO","","",-1,-1,0,"","_self","","","","",1]);
stm_bpx("p2","p1",[1,4,0,0,0,7,34]);
stm_aix("p2i0","p1i2",[0,"PRODUCTS","","",-1,-1,0,"products.html","_self","","","","",34]);
stm_aix("p2i1","p1i3",[0,"PROCESS","","",-1,-1,0,"process.html"]);
stm_ep();
stm_aix("p0i2","p1i0",[0,"FUTABA GROUP","","",-1,-1,0,"","_self","","","","",0,5,0,"arrow_r.gif","arrow_r.gif",7,7]);
stm_bpx("p3","p1",[1,4,0,0,0,7,45]);
stm_aix("p3i0","p1i0",[0,"GLOBAL","","",-1,-1,0,"global.html","_self","","","","",45]);
stm_aix("p3i1","p1i2",[0,"HISTORY","","",-1,-1,0,"futaba_history.html"]);
stm_ep();
stm_ep();
stm_em();
//-->
</script>
</div>
<div id="apDiv5"><a href="http://www.dhtml-menu-builder.com" style="display:none;visibility:hidden;">Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com</a>
<script type="text/javascript">
<!--
stm_bm(["menu2215",900,"","blank.gif",0,"","",0,0,250,0,1000,1,0,0,"","",0,0,1,2,"default","hand","",1,25],this);
stm_bp("p0",[0,4,0,0,0,7,10,7,100,"",-2,"",-2,50,0,0,"#999999","transparent","bg_01.gif",3,1,1,"#000000"]);
stm_ai("p0i0",[0,"COMMITMENT","","",-1,-1,0,"","_self","","","","",1,5,0,"arrow_r.gif","arrow_r.gif",7,7,0,2,1,"#FFFFF7",1,"#993333",1,"bg_06_edit_down.gif","bg_06_edit.gif",3,1,7,1,"#000000","#000000","#009900","#FFFFFF","bold 9pt Arial","bold 9pt Arial",0,0,"","","","",0,0,0]);
stm_bpx("p1","p0",[1,4,0,0,0,7,32,0]);
stm_aix("p1i0","p0i0",[0,"QUALITY","","",-1,-1,0,"quality.html","_self","","","","",32,5,0,"","",0,0]);
stm_aix("p1i1","p0i0",[0,"OUR GOALS","","",-1,-1,0,"goals.html","_self","","","","",0,5,0,"","",0,0,0,1]);
stm_ep();
stm_aix("p0i1","p1i1",[0,"JOIN FIUK","","",-1,-1,0,"","_self","","","","",10,5,0,"arrow_r.gif","arrow_r.gif",7,7]);
stm_bpx("p2","p1",[1,4,0,0,0,7,8]);
stm_aix("p2i0","p1i0",[0,"VACANCIES","","",-1,-1,0,"vacancies.html","_self","","","","",8]);
stm_aix("p2i1","p1i1",[0,"APPLICATION","","",-1,-1,0,"application.php"]);
stm_ep();
stm_aix("p0i2","p0i1",[0,"CONTACT FIUK","","",-1,-1,0,"","_self","","","","",3]);
stm_bpx("p3","p1",[1,4,0,0,0,7,47]);
stm_aix("p3i0","p1i1",[0,"CONTACT","","",-1,-1,0,"contact.php","_self","","","","",47]);
stm_aix("p3i1","p1i0",[0,"LOCATION","","",-1,-1,0,"location.html","_self","","","","",0]);
stm_ep();
stm_ep();
stm_em();
//-->
</script>
</div>
<div id="apDiv6"></div>
<div id="apDiv7"><script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("<small><font color='green' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></font></small>")
</script></div>
<div id="apDiv10"></div>
<div id="apDiv12"></div>Please use this form for any enquiry you wish to make to FIUK.<br />
<br />
<div class="bodyfont" id="apDiv13"> <table width="99%" border="0" align="center">
<tr>
<td colspan="3"><span class="bodyfont">Thank you for your application, we will get back to you as soon as possible.</span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="68%"><span class="bodyfont">You will be automatically redirected to our homepage in </span></td>
<td width="3%"><div class="bodyfont" id="countDown"></div></td>
<td width="29%"><span class="bodyfont">seconds.</span></td>
</tr>
</table></div>
</div>
</body>
</html>

Thanks in advance,

Matt