1.11M Members

Need help in sending uploaded file along with other data in a web form

 
0
 

Hello,
I need my web users to send an uploaded file along with their registration data.
The form will be sent via email while at the same time, the uploaded file will be stored in a folder on my server.
Take a look at the code please:

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "example@noexample.com";
	$email_subject = "Abstract Submission Via Journal Website";
	
	
	function died($error) {
		// your error code can go here
		echo "We are very sorry, but there were error(s) found with the form you submitted. ";
		echo "These errors appear below.<br /><br />";
		echo $error."<br /><br />";
		echo "Please go back and fix these errors.<br /><br />";
		die();
	}
	
	// validation expected data exists
	if(!isset($_POST['first_author_title']) ||
		!isset($_POST['first_author_surname']) ||
		!isset($_POST['first_author_othernames']) ||
		!isset($_POST['second_author_title']) ||
		!isset($_POST['second_author_surname']) ||
		!isset($_POST['second_author_othernames']) ||
		!isset($_POST['third_author_title']) ||
		!isset($_POST['third_author_surname']) ||
		!isset($_POST['third_author_othernames']) ||
		!isset($_POST['presentation_type']) ||
		!isset($_POST['subject_classification']) ||
		!isset($_POST['presentation_title']) ||
		!isset($_POST['first_author_org']) ||
		!isset($_POST['first_author_phone']) ||
		!isset($_POST['first_authoe_email']) ||
		!isset($_POST['second_author_org']) ||
		!isset($_POST['second_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['third_author_org']) ||
		!isset($_POST['third_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['abstract_uploaded'])) {
		died('We are sorry, you did not fill in required information listed above. Please do so.');		
	}
	
	$first_author_title = $_POST['first_author_title']; // required
	$first_author_surname = $_POST['first_author_surname']; // required
	$first_author_othernames = $_POST['first_author_othernames']; // required
	$second_author_title = $_POST['second_author_title']; // required
	$second_author_surname = $_POST['second_author_surname']; // required
	$second_author_othernames = $_POST['second_author_othernames']; // required
	$third_author_title = $_POST['third_author_title']; // required
	$third_author_surname = $_POST['third_author_surname']; // required
	$third_author_othernames = $_POST['third_author_othernames']; // required
	$presentation_type = $_POST['presentation_type']; // required
	$subject_classification = $_POST['subject_classification']; // required
	$presentation_title = $_POST['presentation_title']; // required
	$first_author_org = $_POST['first_author_org']; // required
	$first_author_phone = $_POST['first_author_phone']; // required
	$first_author_email = $_POST['first_author_email']; // required
	$second_author_org = $_POST['second_author_org']; // required
	$second_author_phone = $_POST['second_author_phone']; // required
	$second_author_email = $_POST['second_author_email']; // required
	$third_author_org = $_POST['third_author_org']; // required
	$third_author_phone = $_POST['third_author_phone']; // required
	$third_author_email = $_POST['third_author_email']; // required
	$abstract_uploaded = $_POST['abstract_uploaded']; // required
		
	$email_message .= "first_author_title: ".clean_string($first_name)."\n";
	$email_message .= "first_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "first_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "second_author_title: ".clean_string($first_name)."\n";
	$email_message .= "second_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "second_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "third_author_title: ".clean_string($first_name)."\n";
	$email_message .= "third_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "third_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "presentation_type: ".clean_string($first_name)."\n";
	$email_message .= "subject_classification: ".clean_string($subject_classification)."\n";
	$email_message .= "presentation_title: ".clean_string($presentation_title)."\n";
	$email_message .= "first_author_org: ".clean_string($first_author_org)."\n";
	$email_message .= "first_author_phone: ".clean_string($first_author_phone)."\n";
	$email_message .= "first_author_email: ".clean_string($first_author_email)."\n";
	$email_message .= "second_author_org: ".clean_string($second_author_org)."\n";
	$email_message .= "second_author_phone: ".clean_string($second_author_phone)."\n";
	$email_message .= "second_author_email: ".clean_string($second_author_email)."\n";
	$email_message .= "third_author_org: ".clean_string($third_author_org)."\n";
	$email_message .= "third_author_phone: ".clean_string($third_author_phone)."\n";
	$email_message .= "third_author_email: ".clean_string($third_author_email)."\n";
	$email_message .= "abstract_uploaded: ".clean_string($abstract_uploaded)."\n";
	
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?
}
?>

<!-- THE PHP SCRIPT I USED FOR PROCESSING THE FILE UPLOAD STARTS HERE -->
<?php 
 $target = "abstract_submitted/"; 
 $target = $target . basename( $_FILES['abstract_uploaded']['name']) ; 
 $ok=1; 
 
 //This is our size condition 
 if ($uploaded_size > 350000) 
 { 
 echo "Your file is too large.<br>"; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 
 
 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 
 
 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['abstract_ uploaded']['tmp_name'], $target)) 
 { 
 echo "The file ". basename( $_FILES['abstract_uploaded']['name']). " has been uploaded"; 
 } 
 else 
 { 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 } 
 ?>

A prompt assistance will be much appreciated. Thanks.

 
0
 

It would be helpful if you stated which error you have, or what part is not working. Just pasting a piece of code won't get you much assistence.

 
0
 

Thanks for the after thought. On pushing the button, the php script file echo "Sorry, there was a problem uploading your file." as indicated on line 140 of the script. Also, no data was delivered to the email account indicated. I hope this sheds some light on the issue.

 
0
 

You did change the $email_to I hope. Also, there is a space on line 134 that should not be there.

 
0
 

I have noticed the space that was not suppose to be there and corrected it however, I seem not to comprehend the $email_to you hinted at. Please a bit more explanation may prove useful.

 
0
 

Line 94 uses $email_to. This variable is set on line 5 to a non existant address. Change that line.

 
0
 

Pritaeas, thanks for your observations. I could get the uploaded files sent to the destination directory successfully however, the form data could not be sent to the genuine email address (not the one I specified in the code I posted). I cold get the uploaded file but the form data was not delivered.
Please advise.

 
0
 

$email_from is never given a value...

 
0
 

I am yet to resolve this issue. Will someone look into why this script would upload file to my server successfully but not send the form data via email.

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "me@myemailaddress.com";
	$email_subject = "Abstract Submission Via Journal Website";
	
	
	function died($error) {
		// your error code can go here
		echo "We are very sorry, but there were error(s) found with the form you submitted. ";
		echo "These errors appear below.<br /><br />";
		echo $error."<br /><br />";
		echo "Please go back and fix these errors.<br /><br />";
		die();
	}
	
	// validation expected data exists
	if(!isset($_POST['first_author_title']) ||
		!isset($_POST['first_author_surname']) ||
		!isset($_POST['first_author_othernames']) ||
		!isset($_POST['second_author_title']) ||
		!isset($_POST['second_author_surname']) ||
		!isset($_POST['second_author_othernames']) ||
		!isset($_POST['third_author_title']) ||
		!isset($_POST['third_author_surname']) ||
		!isset($_POST['third_author_othernames']) ||
		!isset($_POST['presentation_type']) ||
		!isset($_POST['subject_classification']) ||
		!isset($_POST['presentation_title']) ||
		!isset($_POST['first_author_org']) ||
		!isset($_POST['first_author_phone']) ||
		!isset($_POST['first_authoe_email']) ||
		!isset($_POST['second_author_org']) ||
		!isset($_POST['second_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['third_author_org']) ||
		!isset($_POST['third_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['abstract_uploaded'])) {
		died('We are sorry, you did not fill in required information listed above. Please do so.');		
	}
	
	$first_author_title = $_POST['first_author_title']; // required
	$first_author_surname = $_POST['first_author_surname']; // required
	$first_author_othernames = $_POST['first_author_othernames']; // required
	$second_author_title = $_POST['second_author_title']; // required
	$second_author_surname = $_POST['second_author_surname']; // required
	$second_author_othernames = $_POST['second_author_othernames']; // required
	$third_author_title = $_POST['third_author_title']; // required
	$third_author_surname = $_POST['third_author_surname']; // required
	$third_author_othernames = $_POST['third_author_othernames']; // required
	$presentation_type = $_POST['presentation_type']; // required
	$subject_classification = $_POST['subject_classification']; // required
	$presentation_title = $_POST['presentation_title']; // required
	$first_author_org = $_POST['first_author_org']; // required
	$first_author_phone = $_POST['first_author_phone']; // required
	$first_author_email = $_POST['first_author_email']; // required
	$second_author_org = $_POST['second_author_org']; // required
	$second_author_phone = $_POST['second_author_phone']; // required
	$second_author_email = $_POST['second_author_email']; // required
	$third_author_org = $_POST['third_author_org']; // required
	$third_author_phone = $_POST['third_author_phone']; // required
	$third_author_email = $_POST['third_author_email']; // required
	$abstract_uploaded = $_POST['abstract_uploaded']; // required
		
	$email_message .= "first_author_title: ".clean_string($first_name)."\n";
	$email_message .= "first_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "first_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "second_author_title: ".clean_string($first_name)."\n";
	$email_message .= "second_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "second_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "third_author_title: ".clean_string($first_name)."\n";
	$email_message .= "third_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "third_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "presentation_type: ".clean_string($first_name)."\n";
	$email_message .= "subject_classification: ".clean_string($subject_classification)."\n";
	$email_message .= "presentation_title: ".clean_string($presentation_title)."\n";
	$email_message .= "first_author_org: ".clean_string($first_author_org)."\n";
	$email_message .= "first_author_phone: ".clean_string($first_author_phone)."\n";
	$email_message .= "first_author_email: ".clean_string($first_author_email)."\n";
	$email_message .= "second_author_org: ".clean_string($second_author_org)."\n";
	$email_message .= "second_author_phone: ".clean_string($second_author_phone)."\n";
	$email_message .= "second_author_email: ".clean_string($second_author_email)."\n";
	$email_message .= "third_author_org: ".clean_string($third_author_org)."\n";
	$email_message .= "third_author_phone: ".clean_string($third_author_phone)."\n";
	$email_message .= "third_author_email: ".clean_string($third_author_email)."\n";
	$email_message .= "abstract_uploaded: ".clean_string($abstract_uploaded)."\n";
	
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

			</br>
			</br>
			</br>
			</br>
			</br>
			</br>
			</br><span class="style19">Your registration was successful. Thank you.
			
			</span>

<?
}
?>
<!-- End of the registration to email script -->

<!-- THE PHP SCRIPT I USED FOR PROCESSING THE FILE UPLOAD STARTS HERE -->
<?php 
 $target = "abstract_submitted/"; 
 $target = $target . basename( $_FILES['abstract_uploaded']['name']) ; 
 $ok=1; 
 
 //This is our size condition 
 if ($uploaded_size > 350000) 
 { 
 echo "Your file is too large.<br>"; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 
 
 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 
 
 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['abstract_uploaded']['tmp_name'], $target)) 
 { 
 echo "The file ". basename( $_FILES['abstract_uploaded']['name']). " has been uploaded"; 
 } 
 else 
 { 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 } 
 ?>

What could be wrong? I need you guys' advice.

 
0
 

See previous comment, still unresolved.

 
0
 

Am I right?

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "emiola@qestinfosystems.com";
	$email_subject = "Abstract Submission Via Journal Website";
	
	
	function died($error) {
		// your error code can go here
		echo "We are very sorry, but there were error(s) found with the form you submitted. ";
		echo "These errors appear below.<br /><br />";
		echo $error."<br /><br />";
		echo "Please go back and fix these errors.<br /><br />";
		die();
	}
	
	// validation expected data exists
	if(!isset($_POST['first_author_title']) ||
		!isset($_POST['first_author_surname']) ||
		!isset($_POST['first_author_othernames']) ||
		!isset($_POST['second_author_title']) ||
		!isset($_POST['second_author_surname']) ||
		!isset($_POST['second_author_othernames']) ||
		!isset($_POST['third_author_title']) ||
		!isset($_POST['third_author_surname']) ||
		!isset($_POST['third_author_othernames']) ||
		!isset($_POST['presentation_type']) ||
		!isset($_POST['subject_classification']) ||
		!isset($_POST['presentation_title']) ||
		!isset($_POST['first_author_org']) ||
		!isset($_POST['first_author_phone']) ||
		!isset($_POST['first_authoe_email']) ||
		!isset($_POST['second_author_org']) ||
		!isset($_POST['second_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['third_author_org']) ||
		!isset($_POST['third_author_phone']) ||
		!isset($_POST['second_author_email']) ||
		!isset($_POST['abstract_uploaded'])) {
		died('We are sorry, you did not fill in required information listed above. Please do so.');		
	}
	
	$first_author_title = $_POST['first_author_title']; // required
	$first_author_surname = $_POST['first_author_surname']; // required
	$first_author_othernames = $_POST['first_author_othernames']; // required
	$second_author_title = $_POST['second_author_title']; // required
	$second_author_surname = $_POST['second_author_surname']; // required
	$second_author_othernames = $_POST['second_author_othernames']; // required
	$third_author_title = $_POST['third_author_title']; // required
	$third_author_surname = $_POST['third_author_surname']; // required
	$third_author_othernames = $_POST['third_author_othernames']; // required
	$presentation_type = $_POST['presentation_type']; // required
	$subject_classification = $_POST['subject_classification']; // required
	$presentation_title = $_POST['presentation_title']; // required
	$first_author_org = $_POST['first_author_org']; // required
	$first_author_phone = $_POST['first_author_phone']; // required
	$first_author_email = $_POST['first_author_email']; // required
	$second_author_org = $_POST['second_author_org']; // required
	$second_author_phone = $_POST['second_author_phone']; // required
	$second_author_email = $_POST['second_author_email']; // required
	$third_author_org = $_POST['third_author_org']; // required
	$third_author_phone = $_POST['third_author_phone']; // required
	$third_author_email = $_POST['third_author_email']; // required
	$abstract_uploaded = $_POST['abstract_uploaded']; // required
	$email_from = $_POST['first_author_email']; // required


	
	$email_message .= "first_author_title: ".clean_string($first_name)."\n";
	$email_message .= "first_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "Email: ".clean_string($email_from)."\n";
	$email_message .= "first_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "second_author_title: ".clean_string($first_name)."\n";
	$email_message .= "second_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "second_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "third_author_title: ".clean_string($first_name)."\n";
	$email_message .= "third_author_surname: ".clean_string($first_name)."\n";
	$email_message .= "third_author_othernames: ".clean_string($first_name)."\n";
	$email_message .= "presentation_type: ".clean_string($first_name)."\n";
	$email_message .= "subject_classification: ".clean_string($subject_classification)."\n";
	$email_message .= "presentation_title: ".clean_string($presentation_title)."\n";
	$email_message .= "first_author_org: ".clean_string($first_author_org)."\n";
	$email_message .= "first_author_phone: ".clean_string($first_author_phone)."\n";
	$email_message .= "first_author_email: ".clean_string($first_author_email)."\n";
	$email_message .= "second_author_org: ".clean_string($second_author_org)."\n";
	$email_message .= "second_author_phone: ".clean_string($second_author_phone)."\n";
	$email_message .= "second_author_email: ".clean_string($second_author_email)."\n";
	$email_message .= "third_author_org: ".clean_string($third_author_org)."\n";
	$email_message .= "third_author_phone: ".clean_string($third_author_phone)."\n";
	$email_message .= "third_author_email: ".clean_string($third_author_email)."\n";
	$email_message .= "abstract_uploaded: ".clean_string($abstract_uploaded)."\n";
	
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

			</br>
			</br>
			</br>
			</br>
			</br>
			</br>
			</br><span class="style19">Your registration was successful. Thank you.
			
			</span>

<?
}
?>
<!-- End of the registration to email script -->

<!-- THE PHP SCRIPT I USED FOR PROCESSING THE FILE UPLOAD STARTS HERE -->
<?php 
 $target = "abstract_submitted/"; 
 $target = $target . basename( $_FILES['abstract_uploaded']['name']) ; 
 $ok=1; 
 
 //This is our size condition 
 if ($uploaded_size > 350000) 
 { 
 echo "Your file is too large.<br>"; 
 $ok=0; 
 } 
 
 //This is our limit file type condition 
 if ($uploaded_type =="text/php") 
 { 
 echo "No PHP files<br>"; 
 $ok=0; 
 } 
 
 //Here we check that $ok was not set to 0 by an error 
 if ($ok==0) 
 { 
 Echo "Sorry your file was not uploaded"; 
 } 
 
 //If everything is ok we try to upload it 
 else 
 { 
 if(move_uploaded_file($_FILES['abstract_uploaded']['tmp_name'], $target)) 
 { 
 echo "The file ". basename( $_FILES['abstract_uploaded']['name']). " has been uploaded"; 
 } 
 else 
 { 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 } 
 ?>

For Pritaeas

 
0
 

At least now it is set.

 
0
 

Remove the error suppression (@) from the mail function on line 98. After this, run a test and see if you get any errors.

If the above didn't help, try putting this at the top of your code:

error_reporting(-1);
ini_set('display_errors','On');

and let us know what comes up.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: