View Single Post
  #1 (permalink)  
Old Apr 21st, 2008, 22:36
jjpeacha jjpeacha is offline
Junior Member
Join Date: Apr 2007
Location: England
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
File Upload Contact Form

Hey!
Well basicly I have made a contact form for users to apply for a job. I have made a php contact form before with relative ease, however i'm finding it hard to get their CV uploaded and attached to an email. I can get all the data put into a email and sent I just dont know how to attach the uploaded file. I took a look at how this company here do it (http://www.freeformmaker.com/) but I found their code really messy and hard to understand but if they can do it I'm sure its possible.

***UPDATE***

I created a code which should send the email and then upload the cv to the server and put a link to it in the email. However whenever I attach a word document it won't load and the error message I get is:

Code: Select all
the server unexpectedly dropped the connection, which sometimes occurs when the server is busy. You might be able to open the page later.
But I know it's not. Below is a copy of the form and the job_form.php that contains all the form scripting.

Code: Select all
<table width="412" height="280" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="410"><form action="job_form.php" method="post" enctype="multipart/form-data" name="jobform">
<p><span class="style3">Work With Us</span></p>
<table width="420" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="20%"><div align="right">Name</div></td>
<td width="3%">:</td>
<td colspan="2"><input name="name" type="text" id="name" size="30" /></td>
</tr>
<tr>
<td><div align="right">Surname</div></td>
<td>:</td>
<td colspan="2"><input name="surname" type="text" id="surname" size="30" /></td>
</tr>
<tr>
<td><div align="right">Email</div></td>
<td>:</td>
<td colspan="2"><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td><div align="right">Curriculum</div></td>
<td>:</td>
<td colspan="2"><input type="file" name="cv" id="cv" /></td>
</tr>
<tr>
<td><div align="right">Wanted</div></td>
<td>:</td>
<td colspan="2"><select name="wanted" id="wanted">
  <option value="collaboration">Collaboration</option>
  <option value="recruitment">Recruitment</option>
</select></td>
</tr>
<tr>
  <td><div align="right">What are you interested in</div></td>
  <td>:</td>
  <td width="39%" align="left" valign="top"><span class="style2">
    <label>
      <input type="checkbox" name="administration" id="administration" />
      Administration<br />  
      <input type="checkbox" name="commercial" id="commercial" />
      Commercial<br />  
      <input type="checkbox" name="lineworker" id="lineworker" />
      Line Worker<br />  
      <input type="checkbox" name="qualityoffice" id="qualityoffice" />
      Quality Office<br />  
      <input type="checkbox" name="miscellaneous" id="miscellaneous" />
      Miscellaneous</label>
  </span></td>
  <td width="38%" align="left" valign="top"><span class="style2">
    <label>
      <input type="checkbox" name="postsale" id="postsale" />
      Post Sale Technical Support</label>
    <br />
    <label>
    <input type="checkbox" name="warehouse" id="warehouse" />
    Warehouse</label>
    <br />
    <label>
    <input type="checkbox" name="secretary" id="secretary" />
    Secretary</label>
    <br />
    <label>
    <input type="checkbox" name="technicaloffice" id="technicaloffice" />
    Technical Office</label>
  </span></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td colspan="2"><input type="submit" name="Submit" value="Submit" />
    <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
PHP: Select all

<?php

@$pfw_ip$_SERVER['REMOTE_ADDR'];
@
$name addslashes($_POST['name']);
@
$surname addslashes($_POST['surname']);
@
$email addslashes($_POST['email']);
@
$cv_Name $_FILES['cv']['name'];
@
$cv_Size $_FILES['cv']['size'];
@
$cv_Temp $_FILES['cv']['tmp_name'];
@
$cv_Mime_Type $_FILES['cv']['type'];
@
$wanted addslashes($_POST['wanted']);
@
$administration addslashes($_POST['administration']);
@
$commercial addslashes($_POST['commercial']);
@
$lineworker addslashes($_POST['lineworker']);
@
$qualityoffice addslashes($_POST['qualityoffice']);
@
$miscellaneous addslashes($_POST['miscellaneous']);
@
$postsale addslashes($_POST['postsale']);
@
$warehouse addslashes($_POST['warehouse']);
@
$secretary addslashes($_POST['secretary']);
@
$technicaloffice addslashes($_POST['technicaloffice']);

function 
RecursiveMkdir($path)
 {
   if (!
file_exists($path)) 
   { 
      
RecursiveMkdir(dirname($path));
      
mkdir($path0777);
    }
  }


if (
strlen($name) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid name</font></p>");
}

if (
strlen($surname) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid surname</font></p>");
}

if (! 
ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+'$email))
{
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid email</font></p>");
}

if (
strlen($email) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid email</font></p>");
}

if( 
$cv_Size == 0)
{
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>");
}
if( 
$cv_Size >2000000)
{
 
unlink($cv_Temp);
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>");
}
if( 
$cv_Mime_Type != "application/msword" AND $cv_Mime_Type != "application/pdf" AND $cv_Mime_Type != "application/rtf" AND $cv_Mime_Type != "application/zip" )
{
unlink($cv_Temp);
die(
"<p align='center'><font face='Arial' size='3' color='#008000'>Please enter a valid cv</font></p>");
}
$uploadFile "../uploads/".$cv_Name ;
if (!
is_dir(dirname($uploadFile)))
  {
    @
RecursiveMkdir(dirname($uploadFile)); 
  }
else
  {
  @
chmod(dirname($uploadFile), 0777);
  }
@
move_uploaded_file$cv_Temp $uploadFile); 
chmod($uploadFile0644);
$cv_URL "http://testdomain.com/uploads/".$cv_Name ;

$pfw_header "From: $email\n"
  
"Reply-To: $email\n";
$pfw_subject "Work With Us - RESPONSE";
$pfw_email_to "test@test.com";
$pfw_message "Visitor's IP: $pfw_ip\n"
"name: $name\n"
"surname: $surname\n"
"email: $email\n"
"cv: $cv_URL\n"
"wanted: $wanted\n"
"administration: $administration\n"
"commercial: $commercial\n"
"lineworker: $lineworker\n"
"qualityoffice: $qualityoffice\n"
"miscellaneous: $miscellaneous\n"
"postsale: $postsale\n"
"warehouse: $warehouse\n"
"secretary: $secretary\n"
"technicaloffice: $technicaloffice\n";
@
mail($pfw_email_to$pfw_subject ,$pfw_message ,$pfw_header ) ;

$pfw_header "From: test@test.com\n"
  
"Reply-To: test@test.com\n";
$pfw_subject "Thanks For Applying";
$pfw_email_to "$email";
$pfw_message "Thanks for applying to join the test team. We will get in contact with you as soon as possible.\n"
"\n"
"Regards,\n"
"\n"
"test";
@
mail($pfw_email_to$pfw_subject ,$pfw_message ,$pfw_header ) ;

 echo(
"<p align='center'><font face='Arial' size='3' color='#008000'>Your Application Has Been Recieved.</font></p>");
?>
Just another quick question - say somebody uploaded a file but there was already a file with the same name on the server, will the script give it a temp name?

Thanks in advance!

Last edited by jjpeacha; Apr 22nd, 2008 at 16:57. Reason: added php coding!
Reply With Quote