Jump to content

Simple Lack of Knowledge


ScottAllenNet

Recommended Posts

Hi Guys,

 

I am having some trouble creating a form process due to a simple lack of knowlegde.

 

Here is my current php code:

 

<?php

$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$attachcv = Trim(stripslashes($_POST['attachcv'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 

// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}

// email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Attach CV: ";
$Body .= $attachcv;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

 

And here is the front end HTML code:

 

<form name="submit-cv" id="submit-cv" action="_layout/php/submit-cv.php" method="post">


<table>
<tbody><tr>
	<td>
		Your Name: <font color="#DA1623">*</font><br />
		<input id="name" class="text" type="text" value="" name="name">
	</td>
	<td>
		Email Address: <font color="#DA1623">*</font><br />
		<input id="email" class="text" type="text" value="" name="email">
	</td>
</tr>
<tr>
	<td>
		Telephone: <font color="#DA1623">*</font><br />
		<input id="telephone" class="text" type="text" value="" name="telephone">
	</td>
	<td>
		Location:<br />
		<input id="location" class="text" type="text" value="" name="location">
	</td>
</tr>

<tr>
	<td colspan="2">
		Attach CV:<br />
		<input type="file" name="attachcv" id="attachcv" /> 
	</td>
</tr>
<tr>
	<td colspan="2">
		Covering Letter:<br />
		<textarea name="coveringletter" rows="5" cols="20"></textarea>
	</td>
</tr>
</tbody></table>

<input type="submit" name="submit" value="Send Details">

</form>

 

 

At the moment, as you can see the attach CV field is a simple text entry field - I want to make this a file upload field which will then attach the file to the email that it sends to me.

 

Any assistance in this would be fantastic.

 

Best,

 

Scott.

Link to comment
https://forums.phpfreaks.com/topic/264602-simple-lack-of-knowledge/
Share on other sites

  • Replies 52
  • Created
  • Last Reply
  Quote

 

 

Thanks for your help but I am still a little lost as to how best integrate that with my existing code.

My suggestion is to start small ie create a simple test file using the tutorial provided above to see how to upload a file. Once you do that you will see how to change your actual scripts.

 

Most new phpers try to do too many things at once. build your scripts in increments. Makes life sooooo much easier when trying to debug.

  Quote

My suggestion is to start small ie create a simple test file using the tutorial provided above to see how to upload a file. Once you do that you will see how to change your actual scripts.

 

Most new phpers try to do too many things at once. build your scripts in increments. Makes life sooooo much easier when trying to debug.

 

Ok so I know have a script that can upload the file but it really throws me on how to email it as an attachment???

 

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

 

 

<?php

// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

I really appreciate your help but I think you overestimate my php abilites. I have no idea how to implement this.

 

What I have produces really is the limit.

 

If possible, can you explain in the simplist of terms, how to turn the following into a form that will upload and email the document along with the form:

 

<form name="submit-cv" id="submit-cv" action="_layout/php/submit-cv.php" method="post">


<table>
<tbody><tr>
	<td>
		Your Name: <font color="#DA1623">*</font><br />
		<input id="name" class="text" type="text" value="" name="name">
	</td>
	<td>
		Email Address: <font color="#DA1623">*</font><br />
		<input id="email" class="text" type="text" value="" name="email">
	</td>
</tr>
<tr>
	<td>
		Telephone: <font color="#DA1623">*</font><br />
		<input id="telephone" class="text" type="text" value="" name="telephone">
	</td>
	<td>
		Location:<br />
		<input id="location" class="text" type="text" value="" name="location">
	</td>
</tr>

<tr>
	<td colspan="2">
		Attach CV:<br />
		<input type="file" name="attachcv" id="attachcv" /> 
	</td>
</tr>
<tr>
	<td colspan="2">
		Covering Letter/Other:<br />
		<textarea name="coveringletter" rows="5" cols="20"></textarea>
	</td>
</tr>
</tbody></table>

<input type="submit" name="submit" value="Send Details">

</form>

 

<?php

// get posted data into local variables
$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 

// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

This should work just fine. I have not personally tested it out. But it looks fine

 

<?php


// upload the file to the server


$filename = basename( $_FILES['uploadedfile']['name']);


// Where the file is going to be placed
$target_path = "uploads/";


/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['file']['name']); 


if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['file']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}


$file = file_get_contents($target_path);


// get posted data into local variables
$EmailFrom = "website@harrisonpearce.com";
$EmailTo = "register@harrisonpearce.com";
$Subject = "New Candidate Registration";
$name = Trim(stripslashes($_POST['name'])); 
$email = Trim(stripslashes($_POST['email'])); 
$telephone = Trim(stripslashes($_POST['telephone'])); 
$location = Trim(stripslashes($_POST['location'])); 
$coveringletter = Trim(stripslashes($_POST['coveringletter'])); 


// validation
$validationOK=true;
if (Trim($name)=="") $validationOK=false;
if (Trim($email)=="") $validationOK=false;
if (Trim($telephone)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
  exit;
}


// prepare email body text
$Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n"
$Body .= "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $telephone;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $location;
$Body .= "\n";
$Body .= "Covering Letter: ";
$Body .= $coveringletter;
$Body .= "\n";
$Body .= "Content-Type: ".mime_content_type($file)."; name=\"" .$target_path. "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-disposition: attachment; file=\"" .$target_path. "\"\r\n" . "\r\n" . chunk_split(base64_encode($file));




// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../sent\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=../../error\">";
}
?>

 

 

I've just updated the code. Saw some syntax errors.

  Quote

missing ';' at end of this line

 

$Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n"

 

 

Thanks buddy - but it now shows this error:

 

 

There was an error uploading the file, please try again!

Fatal error: Call to undefined function mime_content_type() in /homepages/7/d393500880/htdocs/harrisonpearce/_layout/php/submit-cv.php on line 70

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.